0

我的 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 子视图:

    <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 父视图:

<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>

当我设置 expanListView 的适配器并将其可见性更改为可见时,一切正常,但它不显示 groupIndicator 图标。任何人都可以帮助我吗?

4

1 回答 1

1

在方法 getGroupView 尝试使用这个布局 - 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 指示器中检查了它。

希望,我帮你。

于 2013-07-21T22:11:56.153 回答