2012-09-19 76 views
0

我想在單擊特定組時更改組上的圖像。 我已經創建了我自己的自定義基礎適配器來擴展可擴展列表。 而內部getGroupView我有以下代碼來更改展開組的圖像。 但擴展時,圖像在未擴展的組中發生變化。展開組的展開式列表視圖,更改展開式組的圖像

對此有任何解決方案?

public View getGroupView(int groupPosition, boolean isExpanded, 
         View convertView, ViewGroup parent) { 
    ImageView categoryImage = (ImageView) 
    convertView.findViewById(R.id.menu_category_image); 
    category.setText(subItems.get(groupPosition).getCategoryName()); 
    if(isExpanded) { 
     categoryImage.setImageResource(R.drawable.dn_arrow); 
    } else 
     categoryImage.setImageResource(R.drawable.right_arrow); 
    return convertView; 
} 

回答

2

試試這個..

list.setOnGroupClickListener(new OnGroupClickListener() 
{ 
      public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) 
      { 
    //do your stuff here   
       return false; 
      } 
     } 
    }); 

欲瞭解更多信息,嘗試下面的鏈接,在這裏你會得到一些消息.............

http://qtcstation.com/2011/03/working-with-the-expandablelistview-part-1/

OR

http://androidtrainningcenter.blogspot.in/2012/07/android-expandable-listview-simple.html

OR

http://www.coderzheaven.com/2011/04/10/expandable-listview-in-android-using-simpleexpandablelistadapter-a-simple-example/

這可能會幫助你..........

4
((ImageView) convertView.findViewById(R.id.image_group_indicator)) 
     .setImageResource(isExpanded?R.drawable.arrowup:R.drawable.arrowdown); 
+0

的最佳解決方案!只要把它放在'getGroupView()'裏面,你就很好。 –

+0

最佳解決方案!你應該標記爲正確的答案 –