I have a List of Items which I retrieved from my Sqlite DB…
I want to set a Click event for each item. How I can customize this event based on the Item clicked????
Be descriptive… I am a beginner.
This is the method that 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));
}
Call
setOnItemClickListener()on theListView. TheAdapterView.OnItemClickListenerlistener you provide will be given the position (0-based index) and ID (if you were using aCursorAdapter, as you should be, rather than converting theCursorinto anArrayList), so you will know which item was clicked upon.