Instead of
int cat_id = cur.getInt(cur.getColumnIndex("_id"));
String cattitle = cur.getString(cur.getColumnIndex("title"));
int has_sub = cur.getInt(cur.getColumnIndex("has_sub"));
results.add(cat_id + cattitle + has_sub);
create a Category class to contain these values, and use a parameterized ArrayList. Something like
class Category {
public int cat_id;
public String cattitle;
public int has_sub;
public Category(int cat_id, ...) {
// constructor logic here
}
}
and
results.add(new Category(cat_id, cattitle, has_sub));
With this, you can set the onItemClickListener as such:
catlist.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v,
final int position, long id) {
Category clickedCategory = results.get(position);
int id = clickedCategory.cat_id;
// do something with id
}
});
Your ArrayList is the data source of your ArrayAdapter, and position
corresponds to the index of the clicked Category in it.