Adding Image button after Add button is clicked (Android Studio Java)

38 views Asked by At

Is it possible in Android studio to produce an Image Button after I clicked a button like Add Button. If yes, how? I want to make an attendance app wherein if the user clicks Add Class an image button will appear

1

There are 1 answers

2
Sambhav Khandelwal On

We have no idea of which layout of you are using as the parent. But, for the best results of my answer, linear layout is advised.

The thing you are trying to achieve is trying to create dynamic elements. For this, you can create an instance of the ImageButton class and then add it to you layout. This can be dont as follows:

//inside onclick of the add button
ImageButton newView = new ImageButton(context);
parentView.addView(newView);

You can add customisations to the view before adding it to the view.