点击可扩展listview android更改布局

问题描述 投票:3回答:1

我有android项目,我必须更改最后exxpanded组(将崩溃)的布局和单击的组。 onGroupClick方法我有:

   int cnt=list.getChildCount();                    
                //set layout to all groups (for closed group)
                for(int i = 0; i < cnt; i`enter code here`++){
                    View group = adapter.getGroupView(i, false,
                            null, list);
                       LinearLayout childLayout = (LinearLayout) group.findViewById(R.id.newsLayout);                          childLayout.setBackgroundResource(R.layout.group_layout_shape);              
                }
                // set layout of clicked group
                LinearLayout groupLayout = (LinearLayout) v.findViewById(R.id.newsLayout);
                groupLayout.setBackgroundResource(R.layout.group_layout_opened_shape);`enter code here`

它改变了点击组的布局(将扩展),但不会改变组的布局,那个崩溃:(可以帮助我

android layout expandablelistview onclicklistener
1个回答
0
投票

您不应该使用此方法,因为它仅用于使用inflater的图片,颜色,布局,这有一个非常有趣的方法

膨胀(R.layout.childLayout,ParentView,true);

你首先放置你想要膨胀的层,第二个 - 将包含子和第三个的父 - 一个布尔变量必须为true才能膨胀。

活动中的示例:

public class MainActivity extends ActionBarActivity {

LayoutInflater inflater;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
    RelativeLayout parentView= (RelativeLayout) findViewById(R.id.mainLayout);
    View v = (View) inflater.inflate(R.layout.child_layout, parentView, true);
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

}

© www.soinside.com 2019 - 2024. All rights reserved.