2012-12-06 63 views
2

我有一個可擴展列表,並且當您單擊某個子項目而不是一個組時,我想要更改整個佈局。我嘗試選擇像這樣的子項目,它會更改所有項目。在可擴展列表中更改自定義項目的整個佈局onchildclicklistener

while(parent.getChildAt(i)!=null){ 
    do something.. 
} 

下面是代碼:

private OnChildClickListener menuListOnChildClickListener = new OnChildClickListener() 
{ 
    public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) 
    { 
     //change whole layout of whole children with an inflator 
     //change the one clicked with another inflator 
     v.setBackgroundColor(Color.BLACK); 
     Toast.makeText(getApplicationContext(), "Tıklandı"+childPosition, Toast.LENGTH_SHORT).show(); 
     switch(childPosition){ 
      case 1: 
      relativeLayout_sagOrtaEkranlar.setVisibility(v.INVISIBLE); 
      relativeLayout_sagOrtaAnasayfa.setVisibility(v.VISIBLE); 
      break; 
      case 2: 
      relativeLayout_sagOrtaEkranlar.setVisibility(v.VISIBLE); 
      relativeLayout_sagOrtaAkilliEv.setVisibility(v.VISIBLE); 
      relativeLayout_sagOrtaAkilliEvPerde.setVisibility(v.INVISIBLE); 
      relativeLayout_sagOrtaAnasayfa.setVisibility(v.INVISIBLE); 
      break; 
      case 3: 
      relativeLayout_sagOrtaEkranlar.setVisibility(v.VISIBLE); 
      relativeLayout_sagOrtaAkilliEv.setVisibility(v.INVISIBLE); 
      relativeLayout_sagOrtaAkilliEvPerde.setVisibility(v.VISIBLE); 
      relativeLayout_sagOrtaAnasayfa.setVisibility(v.INVISIBLE); 
      break; 
      default: 
      break; 
     } 
     return true; 
    } 

任何解決方案?

回答

0

爲了瞭解孩子的項目,我不得不數的大小(尺寸是一個靜態變量沒有大小()函數)適配器我的適配器的第一個孩子,並同時改變佈局從主childOnClick稱之爲:

int i=0; 
while(parent.getChildAt(i)!=null){ 
    if((i>0 && i<ExpandListAdapter.size)){ 
     c=(ImageView) parent.getChildAt(i).findViewById(R.id.iv_listChild); 
     c.setVisibility(View.VISIBLE); 
     d=(ImageView) parent.getChildAt(i).findViewById(R.id.iv_listChild2); 
     d.setVisibility(View.INVISIBLE); 
    } 
    i++; 
}