I have created multiple button in a layout dynamically.Now,i want to remove clicked button from layout.
for example:-
Asked
Active
Viewed 1,549 times
1

Deepmala singh M
- 379
- 1
- 16
-
onclick of button make its visibility GONE – Manohar Jan 03 '17 at 08:31
-
button.setVisibility(View.INVISIBLE); will give empty space on the place of button – Rathiga Jesika Jan 03 '17 at 08:34
-
1Possible duplicate of [How can I remove a button or make it invisible in Android?](http://stackoverflow.com/questions/4127725/how-can-i-remove-a-button-or-make-it-invisible-in-android) – Manoj Perumarath Jan 03 '17 at 09:21
3 Answers
0
If you want to do it on every buttons you can get them all , then remove the activated ones
ArrayList<View> allButtons;
//Get all buttons from the selected layout, then put them in an arraylist
allButtons =((LinearLayout)findViewById(R.id.button_container)).getTouchables();
//loop on each button and remove the activated ones
foreach (Button b : allButtons){
if (b.isActivated()){
b.setVisibility(View.GONE);
}
}

Topsy
- 1,023
- 1
- 11
- 26
0
LinearLayout parent = new LinearLayout(this);
parent.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
parent.setOrientation(LinearLayout.HORIZONTAL);
for (int i = 0 ; i < 10 ; i++) {
Button b = new Button(this);
b.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
view.setVisibility(View.GONE);
}
});
b.setText("Primary");
Drawable image = ContextCompat.getDrawable(getApplicationContext(), R.drawable.your_image);
image.setBounds(0, 0, 60, 60);
b.setCompoundDrawables(null, null, image, null);
parent.addView(b);
}

Mayur Raval
- 3,250
- 6
- 34
- 57