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);