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 Answer
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.
2 Comments
compsci
Thank you for the answer, btw I am using constraint layout.
Sambhav Khandelwal
For that case, I'd recommend you to create a linear layout only for this view(not a good choice but its the easiest way) and then add this view in that.