I have a category table with two columns category_idand name. I created a data helper class with a name CategoryDataHelper. I have a method with the name of getCategoryCursor()this helper class that retrieves the identifier and name from the category table and returns the cursor. Using this cursor, I used SimpleCursorAdapterto display a list of categories. It is working fine.
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});
setListAdapter(adapter);
list = getListView();
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
}
});
}
}
Now I want to implement OnItemClickListenerand send Intent from the category_idselected category. How can I get the id in a method onItemClick()?
source
share