SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.list_item, c, new String[]{MyDBHelper.KEY_NAME, MyDBHelper.KEY_ID}, new int[]{R.id.field_name});
i.e. leave the KEY_ID at the end of the String[] and do not link it to any View. Create the context menu and get the KEY_ID registerForContextMenu(list); list.setOnCreateContextMenuListener(new OnCreateContextMenuListener() { public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { menu.add(0, 1, 0, R.string.menu_item_delete_user); } }); list.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> adapterView, View v, int arg2, long arg3) { Cursor cursor = (Cursor) adapterView.getItemAtPosition(arg2); int key_id = cursor.getInt(cursor.getColumnIndex(MyDBHelper.KEY_ID)); ... } }); } BR, Adrian Vintu http://www.adrianvintu.com On Thu, Jun 10, 2010 at 3:06 PM, ColletJb <collet...@gmail.com> wrote: > Hi, > > I have a very simple issue i actually can't fix :( > > I have a basic database with fields, let's say "MyDBHelper.KEY_ID, > MyDBHelper.KEY_NAME, MyDBHelper.KEY_DATA" and a listview where i only > display the "MyDBHelper.KEY_NAME" field. > > I used this sample of code : > > Cursor c = data_db.getAll(); > startManagingCursor(c); > SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, > R.layout.list_item, > c, > new String[]{MyDBHelper.KEY_NAME}, > new int[]{R.id.field_name}); > setListAdapter(adapter); > > My problem is, I don't know how i can modify simply this code in order > to get the "MyDBHelper.KEY_ID" value when I click an item on the > listView. > > I suppose it should be something like this : > > Cursor c = data_db.getAll(); > startManagingCursor(c); > SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, > R.layout.list_item, > c, > new String[]{MyDBHelper.KEY_ID, MyDBHelper.KEY_NAME}, > new int[]{R.id.field_id, R.id.field_name}); // How to hide the > KEY_ID > value ? > setListAdapter(adapter); > > Thanks for your help. > > -- > 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 -- 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