我想创建一个连续四个子按钮的可扩展列表。并单击该按钮。我可以在 android studio 中使用什么。我已经检查了很多甚至尝试过ListView
以垂直方式生成子的可扩展。
问问题
85 次
1 回答
2
解决方案 1: 使用 ExpandableListView 并在 group_child_layout 中取四个 ImageView(Whatever Buttons)。
分配相应的数据(例如,将电话号码值分配给 call_icon)。下面的例子:
@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;
}
解决方案 2: 使用 ExpandableListView 并在 group_child_layout 中取一个 RecyclerView(用于水平按钮列表)。下面的例子:
@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;
}
于 2019-06-12T13:41:57.657 回答