2012-07-11 57 views
0

我有如下因素听众和我覆盖的方法onGroupExpand的Android ExpandableListView错误

list.setOnGroupExpandListener(new OnGroupExpandListener() { 

      @Override 
      public void onGroupExpand(int groupPosition) { 
       long groupId = adapter.getGroupId(groupPosition); 
       Toast.makeText(getBaseContext(), "Group = " + adapter.getGroupId(groupPosition), Toast.LENGTH_SHORT).show(); 
       Log.d(TAG, "Group expanded"); 
       View v = adapter.getGroupView((int) groupId, true, null, list); 

       TextView txt = (TextView)v.findViewById(R.id.expandable_first_layer); 
       Log.d(TAG, "txt: " + txt.getText()); 
       txt.setText("Tru-ru-ru"); 
       Log.d(TAG, "txt: " + txt.getText()); 
      } 
     }); 

我看到正确的文本时,我调用txt.getText()第一次。然后在第二个txt.getText()在我的LogCat中看到新的文本。

但问题是ExpandableListView不会更改它在该特定项目中的文本。与在onGroupExpand中设置背景颜色相同。有没有人遇到这个错误?

+0

你必须notifydatasetchange使得该列表中的任何更改后刷新expandablelist。 – Rakshi 2012-07-11 09:56:43

+0

不,adapter.notifyDataSetChanged()不能解决问题。 – Stas 2012-07-11 10:00:40

+0

我不明白为什么你要设置文本,当你扩大名单 – Rakshi 2012-07-11 10:07:00

回答

0

试试这个在getGroupView方法的适配器类检查列表,即国家如果扩展或折叠,如果条件下,如果其扩展可以设置不同的颜色.. 检查下面的代码片段以获取更多信息

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

      convertView.setBackgroundResource(R.color.red); 
      if(isExpanded){ 

      convertView.setBackgroundResource(R.color.blue); 

      } 





     return convertView; 
    } 
+0

我不知道。汗我是复制这个适配器,我有NullPointerException其中convertView.setBackgroundResource(R.color.red); (颜色可用) – Stas 2012-07-12 11:59:14

0

那么你需要通过适当的充气布局得到convertview,否则会给异常