Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 可扩展列表视图自定义设计_Android_Xml_Expandablelistview_Android Custom View_Custom View - Fatal编程技术网

Android 可扩展列表视图自定义设计

Android 可扩展列表视图自定义设计,android,xml,expandablelistview,android-custom-view,custom-view,Android,Xml,Expandablelistview,Android Custom View,Custom View,我想要自定义ExpandableListView,但无法自定义childs。如何制作边框并填充背景(src代码下面的示例) 我所拥有的: ExpandableListView 列出\u片段\u服务\u组.xml 列出\u片段\u服务\u child.xml expandblelistview\u background.xml 我想要的是: 添加: 公共类服务适配器扩展BaseExpandableListAdapter{ 私有静态最终字符串标记=ServicesAdapter.

我想要自定义ExpandableListView,但无法自定义childs。如何制作边框并填充背景(src代码下面的示例)

我所拥有的:

ExpandableListView


列出\u片段\u服务\u组.xml


列出\u片段\u服务\u child.xml


expandblelistview\u background.xml


我想要的是:

添加:

公共类服务适配器扩展BaseExpandableListAdapter{
私有静态最终字符串标记=ServicesAdapter.class.getSimpleName();
私有ArrayList组;
ArrayList儿童;
私人语境;
私有静态字符串GROUP\u NAME=“GROUP\u NAME”;
私有静态字符串GROUP\u IMAGE=“GROUP\u IMAGE”;
私有静态字符串CHILD\u NAME=“CHILD\u NAME”;
公共服务适配器(上下文、ArrayList组、ArrayList子级){
this.context=上下文;
this.group=组;
这个孩子=孩子;
}
@凌驾
public int getGroupCount(){
返回组.size();
}
@凌驾
公共整数getChildrenCount(整数组位置){
返回child.get(groupPosition.size();
}
@凌驾
公共对象getGroup(int-groupPosition){
返回组.get(groupPosition);
}
@凌驾
公共对象getChild(int-groupPosition,int-childPosition){
返回child.get(groupPosition).get(childPosition);
}
@凌驾
公共长getGroupId(int-groupPosition){
返回组位置;
}
@凌驾
公共长getChildId(int-groupPosition,int-childPosition){
返回子位置;
}
@凌驾
公共布尔表ID(){
返回true;
}
@凌驾
公共视图getGroupView(int groupPosition、布尔isExpanded、视图convertView、视图组父级){
if(convertView==null){
LayoutInflater infalInflater=(LayoutInflater)上下文
.getSystemService(上下文布局\充气机\服务);
convertView=infalInflater.充气(R.layout.list\u fragment\u services\u groups,null);
}
如果(扩展){
convertView.setBackgroundResource(R.drawable.expandblelistview\u background\u选中);
}否则{
convertView.setBackgroundResource(R.drawable.expandblelistview\U后台);
}
ImageView imgServicesGroup=(ImageView)convertView.findViewById(R.id.imgServicesGroup);
TextView txtServicesGroup=(TextView)convertView.findViewById(R.id.txtServicesGroup);
txtServicesGroup.setText(group.get(groupPosition.get(group_NAME));
int-imageId=context.getResources().getIdentifier(“ic_”+group.get(groupPosition).get(group_-IMAGE),“drawable”,context.getPackageName());
imgServicesGroup.setImageResource(imageId);
返回视图;
}
@凌驾
公共视图getChildView(int-groupPosition、int-childPosition、布尔isLastChild、视图convertView、视图组父级){
if(convertView==null){
LayoutInflater infalInflater=(LayoutInflater)上下文
.getSystemService(上下文布局\充气机\服务);
convertView=infalInflater.充气(
R.layout.list\u fragment\u services\u child,空);
}
TextView txtServicesChild=(TextView)convertView.findViewById(R.id.txtServicesChild);
txtServicesChild.setText(child.get(groupPosition).get(childPosition.get(child_NAME));
返回视图;
}
@凌驾
公共布尔值isChildSelectable(int-groupPosition,int-childPosition){
返回false;
}
}

你能显示适配器的代码吗?@MarkBuikema是的,我编辑了我的问题。你可以在
getChildView()
方法中设置子视图的样式。@MarkBuikema我知道这一点,但我认为有一种更简单的自定义方法来获取边框,你可以通过
if(getChildCount())检查视图是否是最后一个子视图-1==childPosition)
。如果这是真的,您可以将背景更改为底部边框