Ehm....what's this: ? startActivity(getIntent()); //Restarts activity for menu refresh
On Fri, Dec 10, 2010 at 10:24 AM, pramod.deore <deore.pramo...@gmail.com>wrote: > Hi, Yuvidroid no I had not called startActivity. Here is my code > > public void onCreate(Bundle savedInstanceState) > { > super.onCreate(savedInstanceState); > > try > { > System.out.println ("Inside try"); > //sampleDB = this.openOrCreateDatabase(SAMPLE_DBNAME, > MODE_PRIVATE, null); > sampleDB = this.openOrCreateDatabase(SAMPLE_DBNAME, > MODE_PRIVATE, null); > System.out.println ("Inside try..."); > Cursor c = sampleDB.rawQuery ("SELECT _id,RoomName, > SwitchFullName FROM SwitchTable ",null); > System.out.println (c.getCount()+"%%%%"); > startManagingCursor(c); > > System.out.println ("After startManagingCursor(c))"); > String[] columns = new String[] {"RoomName", > "SwitchFullName"}; > > int[] names = new int[] {R.id.room, R.id.switch1}; > > myAdapter = new SimpleCursorAdapter(this, > R.layout.roomswitchlist, c, columns,names); > setListAdapter(myAdapter); > > > } > catch (SQLiteException se ) > { > Log.e(getClass().getSimpleName(), "Could not create or Open > the database"); > } > finally > { > //sampleDB.close(); > } > > registerForContextMenu(getListView()); > } > > public void onCreateContextMenu(ContextMenu menu, View > v,ContextMenuInfo menuInfo) > { > try > { > info = (AdapterView.AdapterContextMenuInfo) menuInfo; > } > catch (ClassCastException e) > { > e.printStackTrace(); > } > > long id = getListAdapter().getItemId(info.position); > Object obj = getListAdapter().getItem((int) id); > System.out.println ("&&&!!!@@@"+obj.toString()); > str = obj.toString(); > System.out.println ("$$$$$"+str); > /*rName = str.substring(0,str.indexOf("-")); > sName = str.substring(str.indexOf("-")+1); > > test = true;*/ > > for (int i=0;i<menuItems.length;i++) > { > System.out.println (menuItems[i]); > } > > System.out.println ("************************"); > for (int i = 0; i<menuItems.length; i++) > { > menu.add(Menu.NONE, i, i, menuItems[i]); > } > > cursor = (Cursor) myAdapter.getItem((int) id); > //long phoneId = > cursor.getLong(cursor.getColumnIndex(People.PRIMARY_PHONE_ID)); > } > > public boolean onContextItemSelected(MenuItem item) > { > AdapterView.AdapterContextMenuInfo info = > (AdapterView.AdapterContextMenuInfo)item.getMenuInfo(); > int menuItemIndex = item.getItemId(); > > menuItemName = menuItems[menuItemIndex]; > System.out.println ("&&&"+menuItemName); > > System.out.println ("^^^^"+menuItemName); > > if (menuItemName.equalsIgnoreCase("Add Switch")) > { > System.out.println ("Inside Add Switch"); > > } > > else if (menuItemName.equalsIgnoreCase("Remove Switch")) > { > System.out.println ("Inside Remove switch"); > > delRoomName = > cursor.getString(cursor.getColumnIndex("RoomName")-1); > System.out.println ("Delete Room name > "+delRoomName); > delSwitchName = > cursor.getString(cursor.getColumnIndex("SwitchFullName")); > System.out.println ("Delete Room name and switch > name > are"+delRoomName+":"+delSwitchName); > > AlertDialog.Builder alt_bld = new > AlertDialog.Builder(this); > alt_bld.setMessage("Do you want to Delete "+delSwitchName > +" ?") > .setCancelable(false) > .setPositiveButton("Yes", new > DialogInterface.OnClickListener() > { > public void onClick(DialogInterface dialog, int id) > { > // Action for 'Yes' Button > System.out.println ("User click on Yes > button"); > deleteSwitchID(delRoomName,delSwitchName); > } > }) > > .setNegativeButton("No", new > DialogInterface.OnClickListener() > { > public void onClick(DialogInterface dialog, int id) > { > // Action for 'NO' Button > System.out.println ("User click on No > button"); > //dialog.cancel(); > } > }); > AlertDialog alert = alt_bld.create(); > // Title for AlertDialog > alert.setTitle("Confirm"); > // Icon for AlertDialog > alert.setIcon(R.drawable.delete); > alert.show(); > } > > else if (menuItemName.equalsIgnoreCase("Rename")) > { > System.out.println ("Inside Rename switch"); > } > > else if (menuItemName.equalsIgnoreCase("Back")) > { > System.out.println ("User click on back button"); > finish(); > } > > return true; > } > > public void deleteSwitchID(String roomName1,String SwitchName1) > { > > try > { > // // "RoomName = '"+nrnm+"'and SwitchName = > '"+nsnm+"'", > sampleDB = this.openOrCreateDatabase(SAMPLE_DBNAME, > MODE_PRIVATE, > null); > int no = sampleDB.delete(SWITCH_TABLE_NAME, > "RoomName = > '"+roomName1+"' and SwitchName = '"+SwitchName1+"'", null); > System.out.println ("No of deleted rows are"+no); > Toast t = new Toast(this); > t.makeText(this, "Switch deleted", > Toast.LENGTH_SHORT) > .show(); > //this.setListAdapter(new ArrayAdapter<String>(this, > android.R.layout.simple_list_item_1,results)); > //onCreate(savedInstanceState); > startActivity(getIntent()); //Restarts activity for > menu refresh > > } > catch (Exception e) > { > e.printStackTrace(); > } > } > > > } > > > On Dec 10, 2:18 pm, YuviDroid <yuvidr...@gmail.com> wrote: > > Mmmm...it looks like you are still starting a new activity each time an > item > > is deleted. > > Don't call "startActivity()". > > > > On Fri, Dec 10, 2010 at 10:11 AM, pramod.deore <deore.pramo...@gmail.com > >wrote: > > > > > > > > > Hi all, I am developing one application in that I am reading data from > > > database and display it in list using SimpleCursorAdapter class. Last > > > time when I had not used SimpleCursorAdapter class then that time list > > > is not update instantly therefore this time I am using > > > SimpleCursorAdapter. > > > > > But this time is also there is new issue. If suppose there > > > are 4 list item and suppose using contectMenu I show option to delete > > > particular item from list. If i delete that item then list is updated > > > succesfully, but if suppose I want to go back then I want to click on > > > back button 2 times(instead of one). If I deleted 5 items then I have > > > to click 6 times to go back. > > > > > How to handle this problem? > > > > > -- > > > 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<android-developers%2bunsubscr...@googlegroups.com> > <android-developers%2bunsubscr...@googlegroups.com<android-developers%252bunsubscr...@googlegroups.com> > > > > > For more options, visit this group at > > >http://groups.google.com/group/android-developers?hl=en > > > > -- > > YuviDroid > > Check out Launch-X <http://android.yuvalsharon.net/launchx.php> (a > widget to > > quickly access your favorite apps and contacts!) > http://android.yuvalsharon.net > > -- > 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<android-developers%2bunsubscr...@googlegroups.com> > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > -- YuviDroid Check out Launch-X <http://android.yuvalsharon.net/launchx.php> (a widget to quickly access your favorite apps and contacts!) http://android.yuvalsharon.net -- 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