ListView Click event
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 = 开发者_Python百科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 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.
精彩评论