Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/227.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
Android动态删除按钮_Android_Android Layout - Fatal编程技术网

Android动态删除按钮

Android动态删除按钮,android,android-layout,Android,Android Layout,我有一个按钮,当我按下它,我想删除它(而不是使它不可见)。我读到我可以使用layout.removeView(mybutton)来实现这一点,但布局是什么?我怎样才能在我的活动中得到它 Button showQuestion; private void initialize() { showQuestion = (Button) findViewById(R.id.bAnswerQuestionShowQuestion); } public void onClick(View v) {

我有一个按钮,当我按下它,我想删除它(而不是使它不可见)。我读到我可以使用
layout.removeView(mybutton)
来实现这一点,但布局是什么?我怎样才能在我的活动中得到它

Button showQuestion;
private void initialize() {
    showQuestion = (Button) findViewById(R.id.bAnswerQuestionShowQuestion);
}
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.bAnswerQuestionShowQuestion:
                showQuestion.setVisibility(View.INVISIBLE);
                //Here i want to delete the button
                question.setVisibility(View.VISIBLE);
                theAnswer.setVisibility(View.VISIBLE);
                answerQuestion.setVisibility(View.VISIBLE);
                showChoices.setVisibility(View.VISIBLE);
                showHint.setVisibility(View.VISIBLE);
            break;
    }
}


布局是按钮的父布局,通常是相对布局或线性布局

您可以通过以下方式获得:

ViewParent layout = button.getParent();
你可以用

      button.setVisibility(View.GONE);
我有一个按钮,当我按下它,我想删除它(不是使它) 无形的)

=>您的操作如下所示:

 showQuestion.setVisibility(View.INVISIBLE);
尝试:

 showQuestion.setVisibility(View.GONE);

仅供参考,不可见仅隐藏视图,但实际存在并消失隐藏,以及实际删除存在。

布局是“查看您的家长”按钮。网站android开发者禁止进入我的国家功能showQuestion.getParent()。revmoveView不存在
 showQuestion.setVisibility(View.GONE);