私は次のようListViewに入力しているものがありCursorAdapterます:
SimpleCursorAdapter.ViewBinder viewBinder = new SimpleCursorAdapter.ViewBinder() {
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
if(columnIndex == cursor.getColumnIndex(MyTableColumns._ID))
{
view.setTag(cursor.getInt(columnIndex));
}
// some other stuff
}
};
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.my_item_renderer, cursor, from, to);
adapter.setViewBinder(viewBinder);
目的は、クリックされたリストアイテムからIDを取得することです。
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
Object obj = v.getTag();
int myId = Integer.parseInt(obj.toString());
}
ただし、これは常にを返しnullます。私は何を見落としていますか?今のところ、非表示のテキストフィールドを使用していますが、何が間違っているのか知りたいです。