views:

278

answers:

1

I am having a List of Item which I retrieved from my Sqlite DB... I wants to set Click event for each n every item.. How I can customise this event based on Item clicked???? Be Descriptive... I am a Begineer..

The method tht I used to fill data in my List ..

private void fillData() {
 db = new DBAdapter(this);
 db.open();
 ArrayList db_results = new ArrayList();
 //All Category
 //Cursor cursor = db.getAllTitles();

 //Single Category
 Cursor cursor = db.getTitle(1);
 if (cursor.moveToFirst())
    {
        do {          
            db_results.add(cursor.getString(4));
        } while (cursor.moveToNext());
    }
 cursor.close();

    this.list.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, db_results));
}
+1  A: 

Call setOnItemClickListener() on the ListView. The AdapterView.OnItemClickListener listener you provide will be given the position (0-based index) and ID (if you were using a CursorAdapter, as you should be, rather than converting the Cursor into an ArrayList), so you will know which item was clicked upon.

CommonsWare
Hi mark, I am looking to do exactly the same thing. Looking on the web ive seen that what you have suggested is the way to do it but I cant find a decent code sample anywhere.Is there one in your books? If so, page number please :)
Tom
Many of the ListView examples in the books use ListActivity and override onListItemClick(), which (IIRC) gives the same parameters. http://github.com/commonsguy/cw-android/tree/master/Selection/List/ for example.
CommonsWare
Thanks once again Mark, looks like exactly what we need :)
Tom