0

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 1

0

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for the answer, btw I am using constraint layout.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.