2012-11-02 78 views
1

我正在嘗試使用我已經創建的可擴展列表視圖,並更改組列表中其中一個項目的背景顏色。我只想更改主列表中條目的顏色,而不是其下拉的子元素,也就是您單擊的部分來展開或隱藏其他部分。我認爲getGroupView會做到這一點,但我無法弄清楚如何使這項工作。如果這是使用正確的方法,有人可以解釋如何使用它?如果有更好的方法,它是什麼?android在ExpandableListView中更改組的顏色

[編輯]我玩了一些,並想出瞭如何使用getGroupView有點,但我仍然有一個問題。我對我的理解所做的只是改變單個條目的顏色,而不改變它們。下面是代碼:

View listViewRow = findViewById(R.layout.menu_item); 
    listViewRow = myNewAdapter.getGroupView(2, false, listViewRow, expandView); 
    listViewRow.setBackgroundColor(Color.RED); 

其中MENU_ITEM是我使用在擴展列表組佈局文件的名稱,expandView是expandableListView。

回答

0

這種嘗試擴展BaseExpandableListAdapter類

public View getGroupView(int groupPosition, boolean isExpanded, 
    View convertView, ViewGroup parent) { 

    if (convertView == null) { 
    LayoutInflater inflater = (LayoutInflater) myContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    convertView = inflater.inflate(R.layout.group_row, null); 
    } 

    TextView tvGroupName = (TextView) convertView.findViewById(R.id.tvGroupName); 
    tvGroupName.setText(list.get(groupPosition).getYear() +" COLLECTION"); 

    return convertView; 
    } 

OR refrer this

+0

我可能並不完全瞭解你告訴我要做什麼。這段代碼似乎沒有任何東西,當我嘗試使用它時,它並沒有改變任何東西。我想我需要做的是找到一種方法來引用組成下拉菜單超級列表的每個單獨的視圖。 – Dragonfiremalus

+0

我想說一個更好的方式來說這個代碼似乎只是簡單地改變你已有的視圖,但我甚至沒有我需要改變的觀點。我需要得到那個觀點。 – Dragonfiremalus

+0

看到我編輯的答案 –

-3

將這個行,在那裏你想顯示不同的顏色:

- android:textColor="#a60704" 

給你的任何顏色代替:

- #a60704 
0

如果u想改變headerlist變化的顏色headerlist.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:padding="8dp" 
    android:orientation="vertical" 
android:background="@color/colorRed"> 
</LinearLayout> 

- 如果ü要改變的childList變化的顏色childlist.xml試試這個

  • <?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
        android:layout_height="55dip" 
    
    android:layout_marginLeft="@dimen/_15dp" 
    </RelativeLayout>