category_id
と の 2 つの列を持つカテゴリ テーブルがありますname
。という名前のデータ ヘルパー クラスを作成しましたCategoryDataHelper
。getCategoryCursor()
カテゴリ テーブルから ID と名前を取得し、カーソルを返すヘルパー クラスの名前のメソッドがあります。そのカーソルを使用SimpleCursorAdapter
して、カテゴリのリストを表示していました。正常に動作しています。
public class Categories extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
categoryDataHelper = new CategoryDataHelper(getApplicationContext());
Cursor categoryCursor = categoryDataHelper.getCategoryCursor();
ListAdapter adapter = new SimpleCursorAdapter (
this,
android.R.layout.simple_list_item_1,
categoryCursor,
new String[] { CategoryDataHelper.NAME },
new int[] {android.R.id.text1});
// Bind to our new adapter.
setListAdapter(adapter);
list = getListView();
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// Here I want the category_id
}
});
}
}
ここで、選択したカテゴリのOnItemClickListener
インテントを実装して送信したいと思います。メソッドcategory_id
でIDを取得するにはどうすればよいですか?onItemClick()