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
-
I don't understand your question, "create an expandable view as in image?" Do you mean, can I create this pictured UI with an ExpandableListView? – Ifrit Aug 07 '15 at 14:11
-
Yes , I am looking to for the same. – user2699728 Aug 13 '15 at 07:17
5 Answers
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.
- 3,705
- 1
- 22
- 37
-
I believe it as a perfect solution, if the above stated case is valid. – UMESH0492 Aug 09 '15 at 17:00
You can achieve this using custom ExpandableListAdapter. You can have a look on the following liks How to write custom ExpandableListAdapter
- 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
- 2,293
- 2
- 17
- 32
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.
- 958
- 1
- 12
- 14
for expandable listview i have to used below library and its works like charm for me.
- 3,294
- 1
- 19
- 29
