2013-07-21 28 views
0

我在我的xml中有一個ExpandableListView,並且正在使用自定義BaseExpandableListAdapter設置它的適配器。 XML:Android - ExpandableListView未顯示groupIndicator圖標

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

當我設置expanListView的適配器並將其可見性更改爲可見時,一切正常,但它不顯示groupIndicator圖標。任何人都可以幫助我?

的方法getGroupView嘗試使用此佈局
+0

您使用自定義視圖來顯示組視圖.. 查看expdanableView = inflater.inflate(R.layout.estatistica_expanlist_parent,null); 這個問題可能是由於這個觀點。 –

+0

R.layout.estatistica_expanlist_parent是這篇文章中的'XML parentView'代碼。它裏面只有一個textview。我不知道什麼可以= T –

+0

我試圖按照此鏈接:http://myandroidsolutions.blogspot.com.br/2012/08/android-expandable-list-example.html –

回答

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

如果你可以看到這個方法是從diferrent你的。我使用ViewHolderPatter,閱讀它(此代碼更好地工作)。

我檢查了它,在我的組mas指標。

希望,我幫你。

+0

它沒有工作= /我創建了一個新的Android應用程序,我重新創建了這個代碼:http://myandroidsolutions.blogspot.com.br/2012/08/android-expandable-list-example.html他的教程中的確實如何。它沒有顯示組指示器圖標D: - http://img850.imageshack.us/img850/5391/bbhu.png - 也許在我的IDE /模擬器中的錯誤? –

+0

我創建了一個自定義groupIndicator圖標,我不知道原因,但它的工作原理。謝謝您的幫助。 –

+0

沒問題,祝你好運! –