Adarsh Mathew Thomas
Adarsh Mathew Thomas

Reputation: 91

Hide all items on item click except for the clicked item for an Expandable List view

Can anyone tell me how I can hide(not collapsing all items) all the items in an expandable list view except for the one item which is clicked. Can this be done using the adapter class implementation? or Just by hiding the Expandable list view on it's item click and then showing the required view with just one item? My current implementation is done by hiding the view and showing the other one with just one item. Any other way to do this?

Upvotes: 1

Views: 698

Answers (2)

Kinnar Vasa
Kinnar Vasa

Reputation: 407

You can do one thing:

List<String> items, selectedItem;
ExpandableListAdapter adapter;

    view.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            selectedItem = new ArrayList<String>();
            selectedItem.add(items.get(position));
            adapter.notify(selectedItem);
        }
    });

I assume that you have list of string and you set items via ExpandableListAdapter.

Implement above in your fragment/activity.

Now, when user touch on any item, you will get that item and notify adapter with new list where there is only selected item, so other items will be hide.

Upvotes: 1

Parth Bhayani
Parth Bhayani

Reputation: 1924

Yes of course this will be done using the adapter class implementation.

Upvotes: 0

Related Questions