public class CustomExpandableListAdapter extends BaseExpandableListAdapter实现ExpandableListAdapter {
public Context context;
private LayoutInflater vi;
private String[][] data;
int _objInt;
public static Boolean checked[] = new Boolean[1];
private static final int GROUP_ITEM_RESOURCE = R.layout.list_group;
private static final int CHILD_ITEM_RESOURCE = R.layout.list_item;
public CustomExpandableListAdapter(Context context, Activity activity, String[][] data) {
this.data = data;
this.context = context;
vi = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
_objInt = data.length;
}
public String getChild(int groupPosition, int childPosition) {
return data[groupPosition][childPosition];
}
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
public int getChildrenCount(int groupPosition) {
return data[groupPosition].length;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
View v = convertView;
String child = getChild(groupPosition, childPosition);
int id_res = 0;
if(groupPosition == 0){
if(childPosition == 0) id_res = R.mipmap.div2;
if(childPosition == 1) id_res = R.mipmap.div1;
}
else if(groupPosition == 1){
if(childPosition == 0) id_res = R.mipmap.div2;
if(childPosition == 1) id_res = R.mipmap.div1;
}
else if(groupPosition == 2){
if(childPosition == 0) id_res = R.mipmap.div2;
if(childPosition == 1) id_res = R.mipmap.div1;
}
else if(groupPosition == 3){
if(childPosition == 0) id_res = R.mipmap.div2;
if(childPosition == 1) id_res = R.mipmap.div3;
if(childPosition == 2) id_res = R.mipmap.div1;
}
if (child != null) {
v = vi.inflate(CHILD_ITEM_RESOURCE, null);
TextView text = (TextView)v.findViewById(R.id.text1);
ImageView imageview = (ImageView)v.findViewById(R.id.image1) ;
text.setText(Html.fromHtml(child));
imageview.setImageResource(id_res);
}
return v;
}
public String getGroup(int groupPosition) {
return "group-" + groupPosition;
}
public int getGroupCount() {
return data.length;
}
public long getGroupId(int groupPosition) {
return groupPosition;
}
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
View v = convertView;
String group = null;
int id_res = 0;
long group_id = getGroupId(groupPosition);
if(group_id == 0){
group = "Gate Pass";
id_res = R.mipmap.getpass;
}
else if(group_id == 1){
group = "Vessel/Rake";
id_res = R.mipmap.vessel;
}
else if(group_id == 2){
group = "Last leg";
id_res = R.mipmap.lastleg;
}
else if(group_id == 3){
group = "Other";
id_res = R.mipmap.other;
}
if (group != null) {
v = vi.inflate(GROUP_ITEM_RESOURCE, null);
TextView text = (TextView)v.findViewById(R.id.text1);
ImageView imageview = (ImageView)v.findViewById(R.id.image1) ;
ImageView img = (ImageView)v.findViewById(R.id.indicatior);
text.setText(Html.fromHtml(group));
imageview.setImageResource(id_res);
if (isExpanded) {
img.setImageResource(R.drawable.up_arrow);
} else {
img.setImageResource(R.drawable.down_arrow);
}
}
return v;
}
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
public boolean hasStableIds() {
return true;
}
}`我想为一组ExpandableListView中的所有子项绘制一条垂直线。我的子项是TextView,所以我尝试在每个子TextView中绘制一条垂直线,如下所示:
答案 0 :(得分:0)
对于 xml 文件中的垂直线添加view
<View
android:layout_width="1dp"
android:layout_height="fill_parent"
android:background="#FF0000FF" />
根据您的需要调整高度。