这个包含四个按钮的 recyclerview 和 listview 是什么?
What is this recycler view or listview it contains four buttons?
我想创建一个包含四个连续子按钮的可扩展列表。并单击处理该按钮。我可以在 android 工作室中使用什么。我已经检查了很多甚至尝试过以垂直方式生成子项的可扩展 ListView
。
解决方案 1:
使用 ExpandableListView 并在 group_child_layout 中使用四个 ImageView(Whatever Buttons)。
分配相应的数据(例如,将 phone 数值分配给 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;
}
方案二:
使用 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;
}
我想创建一个包含四个连续子按钮的可扩展列表。并单击处理该按钮。我可以在 android 工作室中使用什么。我已经检查了很多甚至尝试过以垂直方式生成子项的可扩展 ListView
。
解决方案 1: 使用 ExpandableListView 并在 group_child_layout 中使用四个 ImageView(Whatever Buttons)。
分配相应的数据(例如,将 phone 数值分配给 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;
}
方案二: 使用 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;
}