I have 1 ListView and two ArrayAdapters
Depending on an if statement, this will happen
listView1.setAdapter(adapter1);
or
listView1.setAdapter(adapter2);
On onCreate(), this is called,
listView1.setAdapter(adapter1);
So listView1.setOnItemClickListener() is connected to adapter 1.
During program execution when listView1.setAdapter(adapter2); is called, the ListView is updated and the display shows the appropriate results, however, clicking an item with the adapter2 results is actually still referencing the adapter1 results.
How do I get the onItemClickListener to switch when listView1’s adapters change?
Thanks
listView1.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent i = new Intent("com.project.DetailView");
i.putExtra("serial", list.get(position).getSerial());
i.putExtra("name", list.get(position).getName());
startActivity(i);
}
});
}
adapter1 = new ArrayAdapter<Object>(this, android.R.layout.simple_list_item_1, list1);
adapter2 = new ArrayAdapter<Object>(this, android.R.layout.simple_list_item_1, list2);
this code may help u.