SimpleCursorAdapter and ViewBinder - Binding data to ListView items to be retrieved on click

后端 未结 2 1107
北荒
北荒 2021-01-21 07:22

So I\'ve got a ListView (using a ListActivity) that I\'m populating from a SQLiteDatabase. I\'m trying to attach the ID (PK) of the row t

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-21 07:33

    This depends on your implementation of R.layout.favorite. If you have this layout contains a parent view with child TextViews for e.g. the tag you set is for the TextViews while the View v received from the onListItemClick() is the parent View. You need to make sure that you receive the tag for the same view you set by using:

        @Override      
        protected void onListItemClick(ListView l, View v, int position, long id) {
        Object wordID = v.getChild(0).getTag();          
        Toast.makeText(getBaseContext(), "ID=" + wordID, 1).show();      
        }    
    

提交回复
热议问题