Hello , Now I had place the code that loads data from the database in a function and called that function when user hit the delete button . But now record gets deleted, but changes are not visible properly. (Properly means suppose there are 2 records and if I delete one record then at this time it shows me 3 records i.e 2 earlier and one after removing one record out of that 2 But actually one record gets successfully deleted. When I restarts the application and see the record then only one record it shows.) Then how to refresh this list view screen?
On Dec 8, 4:47 pm, Kostya Vasilyev <kmans...@gmail.com> wrote: > Also, don't do this: > > startActivity(getIntent()); > > This launches a new activity just like the current one. > > If you need to keep the current activity and update the UI with new > data, just put that code in a function and call it when necessary. > > -- Kostya > > 08.12.2010 14:31, pramod.deore пишет: > > > > > Thanks Kostya for your suggestion and link. > > > On Dec 8, 4:27 pm, Kostya Vasilyev<kmans...@gmail.com> wrote: > >> Pramod, > > >> Move the code that loads data from the database from onCreate to onStart. > > >> See this for an explanation: > > >>http://developer.android.com/guide/topics/fundamentals.html#actlife > > >> ( scroll down to see a very useful flowchart ) > > >> -- Kostya > > >> 08.12.2010 14:08, pramod.deore пишет: > > >>> Hi everybody, > >>> In my application I am displaying list. I have created > >>> ContextMenu. In that there are options like add,remove,back,etc... > >>> Now when I select Remove option then I call method > >>> deleteRecord(), which delete that list record from database. After > >>> that I call method - startActivity(getIntent()); Because of this > >>> method activity restarts and list changes are instantly visible to > >>> user because in start method I had write code that display the list > >>> like. > >>> public void onCreate(Bundle savedInstanceState) > >>> { > >>> super.onCreate(savedInstanceState); > >>> try > >>> { > >>> sampleDB = this.openOrCreateDatabase(SAMPLE_DBNAME, > >>> MODE_PRIVATE, null); > >>> Cursor c = sampleDB.rawQuery ("SELECT RoomName, > >>> SwitchFullName FROM SwitchTable ORDER BY RoomName",null); > >>> int count = c.getCount(); > >>> System.out.println ("Total number of records are"+count); > >>> if (c != null ) > >>> { > >>> if (c.moveToFirst()) > >>> { > >>> do > >>> { > >>> roomName = > >>> c.getString(c.getColumnIndex("RoomName")); > >>> switchName = > >>> c.getString(c.getColumnIndex("SwitchFullName")); > >>> System.out.println > >>> (roomName+":"+switchName); > >>> results.add(roomName+"-"+switchName); > >>> } > >>> while (c.moveToNext()); > >>> c.close(); > >>> } > >>> } > >>> this.setListAdapter(new ArrayAdapter<String>(this, > >>> android.R.layout.simple_list_item_1,results)); > >>> } > >>> catch (SQLiteException se ) > >>> { > >>> Log.e(getClass().getSimpleName(), "Could not create or Open > >>> the database"); > >>> } > >>> finally > >>> { > >>> //sampleDB.close(); > >>> } > >>> registerForContextMenu(getListView()); > >>> } > >>> Now suppose I have list like this > >>> Hall - Fan > >>> Kitchen - AC > >>> Bedroom - tv > >>> and suppose I delete record no 1 then list display as following > >>> Kitchen - AC > >>> Bedroom - tv > >>> It looks perfectly well. But suppose I press the back button then > >>> list is again display as > >>> Hall - Fan > >>> Kitchen - AC > >>> Bedroom - tv > >>> Actually first record is deleted succesfully, but though also it is > >>> displayed when I press back button. How to avoid this problem? > >> -- > >> Kostya Vasilyev -- WiFi Manager + pretty widget > >> --http://kmansoft.wordpress.com > > -- > Kostya Vasilyev -- WiFi Manager + pretty widget > --http://kmansoft.wordpress.com -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en