更改expandablelistview onchildclicklistener中自定义项的整个布局

时间:2012-12-06 15:40:29

标签: android

我有一个expandablelist,我想在你点击一个子项而不是一个组时更改整个布局。我尝试选择这样的子项,它会改变所有项目。

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;
    } 

任何解决方案?

1 个答案:

答案 0 :(得分:0)

为了理解子项,我必须计算适配器中适配器第一个子的大小(大小是静态变量而不是size()函数),并在更改布局时从主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++;
}