Search code examples
javaandroidlistviewandroid-listviewlistviewitem

How to identify which list view item is clicked when using same list view layout for multiple lists in android?


I have created a single dialog box in one function, and passing list view layout resource in it, to make listview inside dialog. I have set onClickItemListener in it to get the listener of what item is clicked. As i am using same dialog box with same list view, having different values. I want to identify which listview is clicked by some unique key. I tried looking in google but didn't find any solution. I am reusing same dialog code with list view for multiple functionality. One time i am showing category, but other time showing type and selecting one using click on item, but not able to identify which click is for type and which one for category.

Please guide me in right direction. Can i set some parameter in listview and read it when item is clicked to parse and get to know which listview is clicked?


Solution

  • As we pass adaptor to the list view and adaptor can give value based on position by overriding function

    @Override
    public String getItem(int position) {
        return this.listItems[position];
    }
    

    I have saved a extra parameter which defines category which this list view belongs and asked adaptor to tell me back in activity from which category this list belong.