Sahan Sahan - 4 months ago 9
Java Question

Check unique list identifier from item on click

guys what's up?
I'm still new to android and creating some testing app.


  • I have two Lists in my view. (Left and Right).

  • List Filled with values.



I trying to add selected list item value to other lists.
For example, If I clicked on an item in a left list. I wanna add selected item to Right list,

implemented OnItemClickListener into my code and OnItemClickListener onItemClick method is firing for both lists.

Any way to identify clicked list in an onItemClick method?
any suggestions are greatly appreciated.

Answer

After reading official API. Found a solution. We can get the ID on the selected list.

public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
    if(adapterView.getId() == R.id.leftList){
        // It's a left list
    }else{
        // It's a Right list
    }
}
Comments