I have three listviews. They scroll together (if I scroll one, then the other scrolls too). But I want each list be clickable separately, because if I click now it get firstly operation one then operation two if I click one more time. So if I scroll one list, then all three of them are scrolled (this is implemented in the code below), but if I click on one of them, I want to do one operation, if I click on other list, then there should be done other operation (and if on the third, then third).
When I tried just to add item listener for each list then it starts the operation #1, #2, #3 consecutively no matter which listview is clicked.
I tried to use getId, but it returns the same id.
Don't know what to do.
public void setUpListeners(final ListView listView, final ListView listView2, final ListView listView3) {
final View[] clickSource = new View[1];
final View[] touchSource = new View[1];
final int offset = 0;
listView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (touchSource[0] == null)
touchSource[0] = v;
if (v == touchSource[0]) {
listView.dispatchTouchEvent(event);
listView3.dispatchTouchEvent(event);
if (event.getAction() == MotionEvent.ACTION_UP) {
clickSource[0] = v;
touchSource[0] = null;
}
}
return false;
}
});
listView3.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (touchSource[0] == null)
touchSource[0] = v;
if (v == touchSource[0]) {
listView.dispatchTouchEvent(event);
listView2.dispatchTouchEvent(event);
if (event.getAction() == MotionEvent.ACTION_UP) {
clickSource[0] = v;
touchSource[0] = null;
}
}
return false;
}
});
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if(view == clickSource[0])
listView2.setSelectionFromTop(firstVisibleItem, view.getChildAt(0).getTop() + offset);
}
});
}
Solved it myself (so this is triple, or double if you remove one, list that scrolls synchronously but each list has its own clicklistener):