Start a Project

How to get data from dynamically created Views android

In this blog,
I will show, how to create the dynamic views and get the data accordingly.

In this example, I am creating some UI elements on the screen at run time. Creating text view, RadioGroup, CheckBox and Spinner dynamically by dummy JSON data and creating the on click listener for button. After clicking on the button I will get the data from each created views and show it.

How to Implement

In this example, I have dynamically created four Types of Views

In this example, I have created above view by dummy JSON Data.

I am using option_name as a Heading

and variant_name as a sub data

option_type specifies the Type of the Views which is gotten from the JSON dummy data.

And I have used an ArrayList for storing the instance of the views.

and store the current view

For getting the data

After the views have created, We have to get the data which is selected in the views.

Then first we have to get the instance of current view

and then by below code you can get the data from spinner

Here I get the variant name of the spinner view but we can get anything which we want to get from views.

Screen-Shots:

Get the Complete Source Code 

MainActivity.java

DummyData.java

activity_main.xml

spiner_row.xml

Exit mobile version