There is no need to pull the ID for each item. And there is definitely no need to put all of this data in an array...!!! Don't do that, you kill performance by causing you to have to load everything out of the cursor.
Note that ListView and many other things rely on a cursor always having a field named "_id" which is the unique identifier for a row. For example, when you use CursorAdapter one of the things it does is retrieve the value of the "_id" row and return that from Adapter.getItemId(). If this concept of "_id" matches your own ID, then just rename your column to "_id" and you are done. When the user clicks, call getItemId() to retrieve that ID for the current position. If these don't match, the first thing you need to do is make sure you do have an "_id" column. This column should be defined this way when you make your table: "_id INTEGER PRIMARY KEY". Now you can't get use Adapter.getItemId() to retrieve your own different ID column, but when the list view is clicked you can use the underlying Cursor to move to the clicked position and retrieve whatever columns you want in that row. The Cursor you pass to ListView can have more columns than those you are showing in the list itself if you need them. On Wed, Apr 27, 2011 at 5:37 AM, Kapil Lokhande <[email protected]>wrote: > Hi Guy, > > Its so simple as you are setting adpter for listview from data structure > e.g. array,arraylist,linkedlist u can use two arraylist or any other in > which one stores name to display on listview and other stores id. now these > two arraylists will have same size. and clicking on one item in list u can > get corresponding id from arraylist with clicked selected position. > hopefully this helps. > > -- > Thanks & Regards, > Kapil Lokhande | Dexter Advisory Pvt. Ltd. <http://dexterltd.com/> | > Android Developer > [image: dexterlogo.jpg] > > > On Wed, Apr 27, 2011 at 3:41 AM, TreKing <[email protected]> wrote: > >> On Sat, Apr 23, 2011 at 12:36 AM, Guy Cothal <[email protected]> wrote: >> >>> HOW DO I GET THE ID FOR THE RECORD >>> >> >> You will have some data structure that holds you data, say Record. This >> will be the content of the Adapter that backs your ListView. When you select >> an item in the ListView it indexes the list of Records, from which you get >> the specific Record instance and it's ID. >> >> If that does not make sense, review ListView, Adapters, and the relevant >> examples in the documentation. >> >> >> ------------------------------------------------------------------------------------------------- >> TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago >> transit tracking app for Android-powered devices >> >> -- >> You received this message because you are subscribed to the Google >> Groups "Android Developers" group. >> To post to this group, send email to [email protected] >> To unsubscribe from this group, send email to >> [email protected] >> 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 [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > -- Dianne Hackborn Android framework engineer [email protected] Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
<<dexterlogo.jpg>>

