android - 如何通过单击取消单击单选按钮来动态删除 LinearLayout?

标签 android radio-button android-linearlayout

这是我添加新线性布局的代码:

public void onClick_addContact(View v)
    {
            LinearLayout layout = (LinearLayout) findViewById(R.id.layoutLinear);
            layout.addView(linearlayout(_intMyLineCount));
            _intMyLineCount++;



    }


    private EditText editText(int _intID) {
            EditText editText = new EditText(this);
            editText.setId(_intID);
            editText.setHint("My lines");
            editText.setWidth(180);         

            editTextList.add(editText);
            return editText;
        }

       private TextView textView(int _intID)
        {
            TextView txtviewAll=new TextView(this);
            txtviewAll.setId(_intID);
            txtviewAll.setText("My lines:");        

            textviewList.add(txtviewAll);
            return txtviewAll;
        }

       private RadioButton button(int _intID)
       {
           RadioButton btn = new RadioButton(this);
           btn.setId(_intID);
           btn.setOnClickListener(newContact);


           return btn;


       }

       OnClickListener newContact = new OnClickListener() {
                //onClick view
                public void onClick(View v) {


                    LinearLayout layout = (LinearLayout) findViewById(R.id.layoutLinear);

                    layout.addView(linearlayout(_intMyLineCount));

                        _intMyLineCount++;


                }
               };

       private LinearLayout linearlayout(int _intID)
        {
            LinearLayout LLMain=new LinearLayout(this);
            LLMain.setId(_intID);       
            LLMain.addView(textView(_intID));
            LLMain.addView(editText(_intID));
            LLMain.addView(button(_intID));
            LLMain.setOrientation(LinearLayout.HORIZONTAL);
            linearlayoutList.add(LLMain);
            return LLMain;

        } 
}

截至目前,如果单击任何单选按钮,则会添加一个新的线性布局。如果单击任何单选按钮,相应的线性布局将被删除,我该如何更改?

最佳答案

使用 setVisibility方法。如果您知道布局的 ID,则可以执行 findViewById,然后使用 myLayout.setVisibility(View.GONE)

关于android - 如何通过单击取消单击单选按钮来动态删除 LinearLayout?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10223712/

相关文章:

javascript - 如何在 ng-repeat 表中查找单选按钮值?

android - 线性布局高度和重量

java - 如何使布局与所有 child 一起平滑地淡入/出现?

java - 尝试在指定时间后更改 Activity 后出错 - "Unfortunately, Application has stopped"

android - Libgdx 设置 UI 在新 GWT 项目中出现 2 个意外错误

android gradle//无检查GradleCompatible

jquery - 单选按钮和 .attr ('checked' ,'checked' )在 IE7 中不起作用

java - 如何使用登录:pass@ url in Glide on Android?

javascript - 在 React 中禁用切换按钮

android - 如何阻止 LinearLayout 宽度?