Custom ExtendedListview Android

Is there a way in android to create an expandable view like in the image? I tried to use Expandable ListView but that doesn't match the value. Please provide, can it be android? thanks in advance

+3


source to share


5 answers


My answer is: Don't use an extensible list adapter.

Your collection doesn't appear to have subcategories (at least less than the scrollable amount). Your strings are just hiding / showing the details of your data, extending the collapse.



use a custom ListAdapter and make each element expandable and show details on button click with animation (you can find height animation by search term).

Hope this helps you.

+4


source


This can be done using a custom ExpandableListAdapter. You can take a look at the following persons How to write your own ExpandableListAdapter



+2


source


I think this is more like a RecyclerView. At least I would use it in this case. The main reason is ViewHolder

. You can of course provide your own implementation of the view pattern, but RecyclerView

forces you to use ViewHolder

and provides stubs.

As far as I understand, you don't need to handle the click on the entire element, but you do need to handle the click on the plus / minus button. So when you implement ViewHolder

, just add a click listener for that view and show / hide content like:

class ChartViewHolder extends RecyclerView.ViewHolder {
    private TextView storeTitle;
    private ToggleButton toggleBtn;
    // other views

    public ViewHolder(View itemView) {
        super(itemView);
        storeTitle = (TextView) itemView.findViewById(R.id.title_id);
        toggleBtn = (ToggleButton) itemView.findViewById(R.id.toggle_id);
        // other views

        toggleBtn.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton toggleButton, boolean isChecked) {
                if(isChecked) {
                    // make content visible
                } else {
                    // make conent invisible
                }
            }
        });
    }
}

      

If you need animation to expand / collapse you should look into property animation

+1


source


Perhaps you need to create a custom ExpandableListAdapter

one that extends BaseExpandableListAdapter

. There are many tutorials. Check out part 15 of this for example.

0


source


for an expandable list i have to use below library and it works like a charm to me.

https://github.com/bmelnychuk/AndroidTreeView

0


source







All Articles