2011-04-15 58 views

回答

0

當然。您只需在創建或重新創建視圖時手動設置視圖的背景。在基於組和兒童地位

1

是的,這是可能的,你必須使用自定義適配器爲您的擴展列表視圖的方法

getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) 

做到這一點的適配器。

@Override 
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, 
      View convertView, ViewGroup parent) { 
     //...... 
     //...... Your code for row view 
     //..... 

     //Now write here code for set colors for rows 
     if(childPosition % 2 == 0) { 
      convertView.setBackgroundColor("#0000FF"); // use this when you want to use hexa value of colors 
     } else { 
      convertView.setBackgroundColor("#FF0000"); // use this when you want to use hexa value of colors 
     } 

     //setBackgroundResource(android.R.color.transparent); // use this for predefined colors at place of setBackground 


     return convertView; 
    } 

閱讀this文章,這裏例如和源代碼也可以。

+0

我得到這個錯誤:「Main2類型的方法getChildView(int,int,boolean,View,ViewGroup)必須覆蓋或實現一個超類型方法」..這可能是因爲我將我的類擴展到Activity而不是BaseExpandableListAdapter? – Omar 2011-04-15 17:41:50