2011-03-21 77 views
2

我有自定義groupViews,它們在展開和摺疊時需要更改狀態。 如果同一組視圖被展開,它將在兩個狀態之間切換。自定義視圖不會使用ExpandableListView上的OnGroupClickListener更新

我遇到的問題是展開方法似乎是拉起一些緩存版本的意見,因爲我的更新在調用expandGroup後不可見。

如果我的監聽器在不調用expandGroup的情況下返回true(處理整個事件本身),則會發生更新。所以expandGroup發生了一些事情,只允許繪製緩存視圖。 我試過無效()幾乎一切。我試着在列表視圖上觸發數據更新事件。我已經嘗試了所有這其他的東西,以及:

expandableList.setGroupIndicator(null); 
     expandableList.setAlwaysDrawnWithCacheEnabled(false); 
     expandableList.setWillNotCacheDrawing(true); 
     expandableList.setItemsCanFocus(false); 

任何那些沒有運氣:(

這裏是我的onClick代碼:

expandableList.setOnGroupClickListener(new OnGroupClickListener() { 

      public boolean onGroupClick(ExpandableListView parent, View v, 
        int groupPosition, long id) { 
       MusicTrackRow mt = (MusicTrackRow) v; 

       if (mt.isPlaying == true) { 
        mt.setPaused(); 
       } else { 
        mt.setPlaying(); 
       } 
       mt.invalidate(); 
       parent.invalidate(); 
       trackAdapter.notifyDataSetInvalidated(); 
//need to call expandGroup if the listener returns true.. if returning false expandGroup is //returned automatically 
           expandableList.expandGroup(groupPosition); //no view refresh 
        return true; 

回答

5

找到了解決辦法終於

展開展開式列表時,適配器中的getGroupview調用將針對列表中的每個組進行調用。 這是您想要更改的地方。 isExpanded參數可讓您確定展開哪個組視圖。

然後你可以做的東西,看起來像這樣:

public View getGroupView(int groupPosition, boolean isExpanded, 
      View convertView, ViewGroup parent) { 
     View v; 
     if (convertView == null) { 
      LayoutInflater inflater = (LayoutInflater) getBaseContext() 
        .getSystemService(LAYOUT_INFLATER_SERVICE); 
      v = inflater.inflate(R.layout.expandablelistitem, null); 

     } else { 
      v = convertView; 
     } 
     int id = (!isExpanded) ? R.drawable.list_plus_selector 
       : R.drawable.list_minus_selector; 

     TextView textView = (TextView) v.findViewById(R.id.list_item_text); 
     textView.setText(getGroup(groupPosition).toString()); 

     ImageView icon = (ImageView) v.findViewById(R.id.list_item_icon); 

     icon.setImageResource(id); 
     return v; 

    } 
相關問題