Reputation: 2382
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
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
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