简体   繁体   中英

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.

I'm not sure if I understand your question, but if you are trying to identify which list was clicked, you can call getId on the view in onItemCLick:

        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            switch (parent.getId()){
                case R.id.left_list:
                    ...
                    break;
                case R.id.right_list:
                    ...
                    break;
            }
        }

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
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM