开发者

ListView Click event

开发者 https://www.devze.com 2022-12-11 13:05 出处:网络
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????

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消