Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
可展开的listview android单击即可更改布局_Android_Layout_Expandablelistview_Onclicklistener - Fatal编程技术网

可展开的listview android单击即可更改布局

可展开的listview android单击即可更改布局,android,layout,expandablelistview,onclicklistener,Android,Layout,Expandablelistview,Onclicklistener,我有一个android项目,我必须改变最后一个exxpanded组(将崩溃)和被点击组的布局。我有以下几种方法: int cnt=list.getChildCount(); //set layout to all groups (for closed group) for(int i = 0; i < cnt; i`enter code here`++){

我有一个android项目,我必须改变最后一个exxpanded组(将崩溃)和被点击组的布局。我有以下几种方法:

   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`
int cnt=list.getChildCount();
//将布局设置为所有组(对于闭合组)
对于(int i=0;i

它会更改单击组的布局(将展开),但不会更改组的布局,即:colapses:(ayone可以帮助我吗?

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

充气(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);
}
}