1

I have created multiple button in a layout dynamically.Now,i want to remove clicked button from layout. for example:-enter image description hereenter image description hereenter image description here

Deepmala singh M
  • 379
  • 1
  • 16

3 Answers3

0

onClick set button.setVisibility(View.GONE);

Rathiga Jesika
  • 357
  • 4
  • 16
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