Answer the question
In order to leave comments, you need to log in
Is it possible to handle two ListViews within the same activity on android?
I'm making a small application that shows multiple ListViews through a ViewFlipper. To process clicks, I use the code found on developer.alexanderklimov.ru/android/views/listview.php , writing it separately for each component.
ArrayAdapter<String> eventAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, events);
lstEvents.setAdapter(eventAdapter);
lstGreetings.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View itemClicked, int position, long id) {
display("for event " + position);
}
});
ArrayAdapter<String> greetAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, greetings);
lstGreetings.setAdapter(greetAdapter);
lstGreetings.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View itemClicked, int position, long id) {
display("for greet " + position);
}
});
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View itemClicked, int position,
long id) {
Toast.makeText(getApplicationContext(), ((TextView) itemClicked).getText(),
Toast.LENGTH_SHORT).show();
}
});
Answer the question
In order to leave comments, you need to log in
Well, you put a listener twice on the same listview.
lstGreetings.setOnItemClickListener
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question