我的xml中有一个ExpandableListView,并且我用自定义的BaseExpandableListAdapter设置了它的适配器。 XML:
<ExpandableListView
android:id="@+id/expanlist_EstatisticaArsenal"
android:divider="@null"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:transcriptMode="alwaysScroll"
android:cacheColorHint="#000000"
android:listSelector="@android:color/transparent"
android:visibility="gone">
</ExpandableListView>
android:visibility="gone"
因为我在某些东西后可以看到它
适配器自定义类:
public class Adapter_expanEstatistica extends BaseExpandableListAdapter {
private Context c;
private List<BlocoArsenal> listblocos;
public Adapter_expanEstatistica(Context ctx, List<BlocoArsenal> listBlocos)
{
c = ctx;
listblocos = listBlocos;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent)
{
// TODO Auto-generated method stub
LayoutInflater inflater = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View expdanableView = inflater.inflate(R.layout.estatistica_expanlist_child, null);
/* Here i populate a tableLayout that exists in expdanableView with some info */
return expdanableView;
}
@Override
public int getChildrenCount(int groupPosition) {
// TODO Auto-generated method stub
return 1;
}
@Override
public int getGroupCount() {
// TODO Auto-generated method stub
return listblocos.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
LayoutInflater inflater = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View expdanableView = inflater.inflate(R.layout.estatistica_expanlist_parent, null);
TextView txt = (TextView) expdanableView.findViewById(R.id.txtNomeBloco);
txt.setText(listblocos.get(groupPosition).getNome());
return expdanableView;
}
@Override
public boolean hasStableIds() {
// TODO Auto-generated method stub
return true;
}
@Override
public boolean isChildSelectable(int arg0, int arg1) {
// TODO Auto-generated method stub
return false;
}
XML ChildView:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/tblEstasticaArsenal" >
</TableLayout>
</LinearLayout>
XML ParentView:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/txtNomeBloco"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:layout_marginTop="3dp"
android:textColor="#5E302A"
android:text="Nome Bloco"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
当我设置vastListView的适配器并将其可见性更改为可见时,一切正常,但它没有显示groupIndicator图标。有人可以帮帮我吗?
答案 0 :(得分:1)
尝试使用此布局 - android.R.layout.simple_expandable_list_item_2
因此,您的代码将如下所示:
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View theConvertView, ViewGroup parent)
{
View row = theConvertView;
TextView textView;
if(theConvertView == null) {
row = inflater.inflate(android.R.layout.simple_expandable_list_item_2, null);
textView = (TextView)row.findViewById(android.R.id.text2);
row.setTag(textView);
} else {
textView = (TextView)theConvertView.getTag();
}
//textView.setText(); //TODO set group
return row;
}
如果你能看到这种方法与你的不同。我使用ViewHolderPatter,阅读它(这段代码更好)。
我在我的组mas指示器中检查了它。
希望,我帮助你。