Custom ExtendedListview Android
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.
source to share
This can be done using a custom ExpandableListAdapter. You can take a look at the following persons How to write your own ExpandableListAdapter
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
source to share