Ali_Waris
Ali_Waris

Reputation: 2382

Android : Creating GUI programmatically at run time in java

I have to create number of buttons and textbox, etc. depending upon a certain number. For ex: if the number = 5, I need to create 5 buttons, and if its value is 10, I need to create 10 buttons.

To achieve such a functionality, the conventional xml GUI won't make it up. I need to develop the GUI dynamically. How can I do that?

Upvotes: 1

Views: 5784

Answers (2)

himanshu munjal
himanshu munjal

Reputation: 321

Add a Linear/Relative layout in xml and on run time according to given number add view(buttons and text views) in this layout. See this tuts: https://androiddesk.wordpress.com/2012/08/05/creating-dynamic-views-in-android/ http://www.javacodegeeks.com/2012/09/android-dynamic-and-xml-layout.html

Upvotes: 2

EE66
EE66

Reputation: 4651

Take a look at RecyclerView. You need to apply the DataSet (what u receive dynamclly) and then let the Adapter handle all of the Binding. Take a look at this tutorial, there are many more. Notice that you will need to create TWO Viewholder (button and a textview) and override the getItemViewType

Upvotes: 3

Related Questions