How to get data from dynamically created Views android

Updated 22 May 2023

Save

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

Screenshot_3

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:

Screenshot_2016-03-16-12-18-08_testapplication.amangupta.myapplicationtest2

Screenshot_2016-03-16-12-24-10_testapplication.amangupta.myapplicationtest2

Get the Complete Source Code 

MainActivity.java

DummyData.java

activity_main.xml

spiner_row.xml

author
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


15 comments

  • Shirisha Reddy
    • Aman Gupta
    • Aman Gupta
  • Milan Amatya
    • Aman Gupta (Moderator)
      • Volkan
        • anchit (Moderator)
        • Dhruv Chauhan
          • anchit (Moderator)
  • ankit
    • anchit (Moderator)
      • cosmas
        • anchit (Moderator)
  • Sandeep
    • anchit (Moderator)
  • Start a Project


      Message Sent!

      If you have more details or questions, you can reply to the received confirmation email.

      Back to Home