3

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

user2699728
  • 377
  • 2
  • 8
  • 25

5 Answers5

4

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.

Ercan
  • 3,705
  • 1
  • 22
  • 37
2

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

Community
  • 1
  • 1
1

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

MightySeal
  • 2,293
  • 2
  • 17
  • 32
0

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.

Erfan GLMPR
  • 958
  • 1
  • 12
  • 14
0

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

https://github.com/bmelnychuk/AndroidTreeView

Darshan Mistry
  • 3,294
  • 1
  • 19
  • 29