2011-03-21 79 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; 

    } 
相关问题