CLOSE ✕
Get in Touch
Thank you for your interest! Please fill out the form below if you would like to work together.

Thank you! Your submission has been received!

Oops! Something went wrong while submitting the form

Add views dynamically to layout in Android

Neelanshi Sharma
|
Android
|
Mar 1, 2021

As Android developer you will surely  need someday to add views dynamically, instead of creating a ListView. This example demonstrates a way to add or remove views to a LinearLayout dynamically.

1. Here we are encapsulating out component in a LinearLayout. RelativLayout defines views at the top that have an EditText which takes in the content to be added and a Button that actually adds the view with the content and inflates it as a child to LinearLayout '@+id/container'.

R.layout.activity_listview2

2 Set onClick listeners for add button in our layout using setOnClickListener and embed one for delete button within it.

And there you go!

Neelanshi Sharma
Neelanshi is a mobile and web developer. She is a computer science major from Banasthali Vidyapith, India.

Recent Blog Posts

Lets Work Together
Contact Me