I want to create a expandable list with four child buttons in a row. And also click working on that buttons. what can i use in android studio. i have checked so many even tried expandable ListView
that is generating child in the vertical manner.
Asked
Active
Viewed 89 times
0
-
did you try creating a recyclerview with a custom layout? – Payam Asefi Jun 12 '19 at 12:49
-
yes but not able to create this view @payam – Rover Jun 12 '19 at 12:50
-
try this library https://github.com/cachapa/ExpandableLayout – Payam Asefi Jun 12 '19 at 12:57
1 Answers
3
Solution 1: Use ExpandableListView and in the group_child_layout take four ImageView(Whatever Buttons).
Assign respective data(e.g assign a phone number value to call_icon). Example below:
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
ChildHolder childHolder = null;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.item_group_child, parent, false);
childHolder = new ChildHolder();
convertView.setTag(childHolder);
}
else {
childHolder = (ChildHolder) convertView.getTag();
}
/* Assign all the buttons their respective data from ContactData object*/
return convertView;
}
Solution 2: Use ExpandableListView and in the group_child_layout take a RecyclerView(for horizontal buttons list) in it. Example below:
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
ChildHolder childHolder = null;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.item_group_child, parent, false);
childHolder = new ChildHolder();
convertView.setTag(childHolder);
}
else {
childHolder = (ChildHolder) convertView.getTag();
}
childHolder.horizontalListView = (RecyclerView) convertView.findViewById(R.id.buttons);
LinearLayoutManager layoutManager = new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);
childHolder.horizontalListView.setLayoutManager(layoutManager);
ButtonsAdapter horizontalListAdapter = new ButtonsAdapter(context, brands.get(groupPosition).buttons);
childHolder.horizontalListView.setAdapter(horizontalListAdapter);
return convertView;
}

Komal Bhalge
- 56
- 5