2

我有一个可扩展列表,当您单击子项而不是组时,我想更改整个布局。我尝试像这样选择子项目,它会更改所有项目。

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

任何解决方案?

4

1 回答 1

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++;
}
于 2012-12-18T07:36:22.303 回答