我有一个按钮,当我按下它时,我想将其删除(而不是使其不可见)。我读到我可以使用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;
}
}
see link http://developer.android.com/reference/android/view/View.html#getParent%28%29
ViewGroup layout = (ViewGroup) button.getParent();
if(null!=layout) //for safety only as you are doing onClick
layout.removeView(button);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)