Reputation: 277
I feel the answer is so obvious but im not noticing it, when I have 2 lists on an activity how do I control the onListItemClick void? so if I want 2 different lists for 2 different sets of information
Upvotes: 0
Views: 54
Reputation: 23638
You should/can use the single onItemClick
method for different ListView
in same activity:
public void onItemClick(AdapterView<?> a, View v, int position, long id) {}
just once. You can then do something like v.getId()
where v
is View
which will give you the id's of your Listview
according to which you can handle the item click listener for more than one ListView
:
v.getId();
and handle the item's click listener for the two `ListView's as below:
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
if( v.getId() == R.id.listView1 )
{
//Your logic for the first listview
}
else if( v.getId() == R.id.listView2 )
{
//Your logic for the second listview
}
}
}
Upvotes: 3
Reputation: 629
you can use two defferent method for listview ::->
tasks_list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View v, int position,
long id) {
// TODO Auto-generated method stub
mapp=true;
Intent i = new Intent(Home_Activity.this,AddTask_Activity.class);
i.putExtra(DBAdapter.KEY_ROW_ID, id);
Log.d("IDD", ""+id);
startActivity(i);
}
});
tasks_list1.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View v, int position,
long id) {
// TODO Auto-generated method stub
mapp=true;
Intent i = new Intent(Home_Activity.this,AddTask_Activity.class);
i.putExtra(DBAdapter.KEY_ROW_ID, id);
Log.d("IDD1", ""+id);
startActivity(i);
}
});
Upvotes: 0