user2699728
user2699728

Reputation: 377

Custom ExpandableListview Android

Is there a way in android to create a expandable view as in image? I tried using Expandable ListView ,but it is not upto the mark as required. Kindly provide if this can be done android ? Thanks in advance

Upvotes: 3

Views: 766

Answers (5)

Darshan Mistry
Darshan Mistry

Reputation: 3372

for expandable listview i have to used below library and its works like charm for me.

https://github.com/bmelnychuk/AndroidTreeView

Upvotes: 0

MightySeal
MightySeal

Reputation: 2315

I think it's more like RecyclerView. At least, i would use it in this case. The main reason is ViewHolder. Of course you can provide your own viewholder pattern implementaion, but RecyclerView forces you to use ViewHolder and provides stubs.

As far as i understand, you don't need to handle click on entire element, but you need to handle click on plus/minus button. So when you implement ViewHolder, simply add click listener for that view and show/hide content, like this:

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 for expanding/collapsing you should look into Property animations

Upvotes: 1

Ercan
Ercan

Reputation: 3705

My answer is: Don't use expandable list adapter.

Your collection doesn't look like having sub collections(at least less then scrollable amount).Your rows just hide/show details of your data by expanding collapsing.

use a custom ListAdapter and make each item expand and show detail on a button click with an Animation (you can find height animation by googling).

I hope this helps you.

Upvotes: 4

Erfan GLMPR
Erfan GLMPR

Reputation: 968

It is possible you should create a custom ExpandableListAdapter which extends BaseExpandableListAdapter. There are lots of tutorials. Check part 15 of this tutorial for example.

Upvotes: 0

user5151031
user5151031

Reputation:

You can achieve this using custom ExpandableListAdapter. You can have a look on the following liks How to write custom ExpandableListAdapter

Upvotes: 2

Related Questions