1

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?

0

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

2 Comments

It seems as an alternative to ListView. I need something which could render a complete GUI as we design it in xml manually.
Its much more abstract and effective then ListView. It should do the trick for u. If it doesnt then edit your question.
2

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

2 Comments

I want to do something similar to this. Can you please share some more details so that I could get an overview of what I need to code.
It depends on your requirement. See links in previous comment for basic idea and then do as per your need. In below example it will add a simple textview to layout.for(int i=0;i<number;++i){ TextView tv=new TextView(con); tv.setText("Your Text"); relative_layout.add(tv); }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.