2016-05-30 47 views
0

你好,我使用此代碼的工作好改變組的背景時,它的用戶點擊組塌陷變化組ExpendbleListView的顏色不是在android系統

expListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() { 

      @Override 
      public boolean onGroupClick(ExpandableListView parent, View v, 
             int groupPosition, long id) { 
       if (!parent.isGroupExpanded(groupPosition)) { 
        v.setBackgroundColor(Color.parseColor("#ff9600")); 
       } else { 
        v.setBackgroundColor(Color.parseColor("#4fc1e9")); 

       } 
       if (parent.isGroupExpanded(groupPosition)) { 
        Toast.makeText(AdieActivity.this,String.valueOf(groupPosition), Toast.LENGTH_SHORT).show(); 
       } 


       return false; 
      } 
     }); 

當用戶點擊組opne,背景顏色是改變了,但問題是,一些組不開放,但該背景也是變化

+0

我想,我必須寫上@覆蓋 公衆查看getGroupView 不在expListView.setOnGroupClickListener 的代碼,它大量的工作 – pouria

回答

1

重寫的方法包含在我的自定義ExpandableListAdapter。

@Override 
public View getGroupView(int groupPosition, boolean isExpanded, 
    View view, ViewGroup parent) 
{ 
    LinearLayout bevGroup = (LinearLayout) view.findViewById(R.id.myid); 

if(isExpanded) 
{ 
    bevGroup.setBackgroundColor(context.getResources().getColor(R.color.bgGroupBlack)); 
} 
else 
{ 
    bevGroup.setBackgroundColor(context.getResources().getColor(R.color.bgTransparent)); 
} 
} 
+0

感謝,什麼是錯在我的代碼??? – pouria

+0

如果(isExpanded)convertView.setBackgroundResource(R.color.select);我使用我的類中的視圖擴展BaseExpandableListAdapter,並且它工作得太 ; } else { convertView.setBackgroundResource(R.color.focuse); } – pouria