I have a button and when I press it, i want to remove it (not make it invisible). I read that I can do that using layout.removeView(mybutton)
but what is the layout ? and how can I get it in my activity
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
ViewGroup layout = (ViewGroup) button.getParent();
if(null!=layout) //for safety only as you are doing onClick
layout.removeView(button);
i have a button and when i press it , i want to remove it (not make it invisible)
=> You did as below:
showQuestion.setVisibility(View.INVISIBLE);
Try with:
showQuestion.setVisibility(View.GONE);
FYI, INVISIBLE just hide the view but physically present there and GONE hide as well remove the presence physically as well.
You can use
button.setVisibility(View.GONE);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With