开发者

how to remove sublayout from the Layout in Android?

I am new to Android.Can anyone give some ideas for my problem.

    /* Parent Linear Layout */

    final LinearLayout par_layout=new LinearLayout(this);
    par_layout.setOrientation(LinearLayout.VERTICAL);

    /* Child Linear Layout */
    final LinearLayout chl_layout=new LinearLayout(this);
    chl_layout.setOrientation(LinearLayout.VERTICAL);

    TextView tv_name=new TextView(this);
    tv_name.setText("Name ");

    TextView tv_item=new TextView(this);
    tv_item.setText("Items ");

    Button btn_submit=new Button(this);
    btn_submit.setText("Submit");
    btn_submit.setOnClickListener(new OnClickListener() {           
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            par_layout.rem开发者_开发知识库oveAllViewsInLayout();                
        }
    });

    chl_layout.addView(tv_name);
    chl_layout.addView(tv_item);
    chl_layout.addView(btn_submit);        
    par_layout.addView(chl_layout); 
    setContentView(par_layout);

In the above code at the time of button click i wish to clear the chl_layout from the par_layout.But i can't . Can anyone give some ideas ??

Note : The following code also not working

 par_layout.removeView(chl_layout);


Use below code to remove child view from parent view.

 par_layout.removeView(chl_layout);


to make whole layout empty there is a void function ...

LinearLayout li=new LinearLayout(this);

li.removeAllViews();


Try using this:

fatherLayout.removeViewInLayout(childLayout);


I can't remove a child view (TableRow) from its parent (TableLayout) with removeView(View view). But addView is working. Strange...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜