I have an custom ExpandableListView Adapter:
public class MyExpandableListView extends BaseExpandableListAdapter {
private Context context;
private List<? extends List<? extends Map<String, ?>>> mChildData;
private List<? extends Map<String, ?>> mGroupData;
public MyExpandableListView(Context context,List<? extends Map<String, ?>> GroupData,
List<? extends List<? extends Map<String, ?>>> ChildData){
this.context = context;
this.mChildData=ChildData;
this.mGroupData=GroupData;
}
@Override
public Object getChild(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return mChildData.get(groupPosition).get(childPosition);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return childPosition;
}
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.child_list_layout, null);
}
TextView childtxt = (TextView) convertView.findViewById(R.id.textView1);
childtxt.setText((CharSequence) mChildData.get(groupPosition).get(childPosition).get("body"));
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
// TODO Auto-generated method stub
return mChildData.get(groupPosition).size();
}
@Override
public Object getGroup(int groupPosition) {
// TODO Auto-generated method stub
return mGroupData.get(groupPosition);
}
@Override
public int getGroupCount() {
// TODO Auto-generated method stub
return mGroupData.size();
}
@Override
public long getGroupId(int groupPosition) {
// TODO Auto-generated method stub
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if(convertView==null){
LayoutInflater infalInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.group_list_layout, null);
}
TextView time = (TextView)convertView.findViewById(R.id.item1);
TextView title = (TextView)convertView.findViewById(R.id.item2);
time.setText((CharSequence) mGroupData.get(groupPosition).get("time"));
title.setText((CharSequence) mGroupData.get(groupPosition).get("titel"));
View view2 = (View)convertView.findViewById(R.id.view2);
view2.bringToFront();
return convertView;
}
@Override
public boolean hasStableIds() {
// TODO Auto-generated method stub
return true;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return true;
}
}
My group_list_layout.xml is following:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<View
android:id="@+id/view2"
android:layout_width="2dp"
android:layout_height="fill_parent"
android:layout_marginLeft="5dp"
android:background="#ff000000" />
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:orientation="horizontal" >
<TextView
android:id="@+id/item1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="row_id"
android:textSize="18sp"
android:width="100dip" />
<TextView
android:id="@+id/item2"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:text="col_1"
android:textSize="18sp"
android:width="300dip" />
</LinearLayout>
</RelativeLayout>
I am trying to display a vertical line in front of the “time” of the group element.
But my view (view2) isn’t displayed. Why?
Your
LinearLayoutis positioned on top of theViewelement. Instead move theViewelement after theLinearLayoutin the group layout so it will be placed above it.Also, inflate your layout like this: