I have just started learning Android and got some misunderstanding. I'm trying to create an application which displays a textView and a button. Every button click generates a random textview. Text view display in second activity using button click.
Asked
Active
Viewed 1,180 times
-1
-
post your code, please. – plsgogame Jul 18 '13 at 12:39
-
You want to generate a random _TEXT_ to fill the textview? – Benjamin Schwalb Jul 18 '13 at 12:40
-
Benjamin Schwalb - yes generate random textview. – Hitesh jadav Jul 18 '13 at 12:44
-
amisuno - i have not any generate textview code give me idea please.. – Hitesh jadav Jul 18 '13 at 12:45
-
A TextView is an object or simply said a container, which may hold TEXT and can have various properties (color, width, height, etc). Do you really want to create multiple TextViews or just use the same TextView but change its text on each button click? Please, clarify your question. – Dzhuneyt Jul 18 '13 at 12:45
-
i want to multiple textview..my application love Quotes. – Hitesh jadav Jul 18 '13 at 12:50
-
1placing randomn textviews sounds like a solid plan for a first-timer on android... – bofredo Jul 18 '13 at 13:00
-
bofredo - can you give me full details. placing randomn textviews sounds like a solid plan for a first-timer on android – Hitesh jadav Jul 18 '13 at 13:05
1 Answers
1
So you are looking for a way to ADD multiple TextViews and set their text? If you want to do it programmatically (because you may also do it from XML, but it won't be dynamic), you need to use something like this:
TextView tv = new TextView(this);
tv.setText("Your quote text");
this.addView(tv);
Note that you may replace this
above with any existing View
object, to which you want to add the TextView.

Dzhuneyt
- 8,437
- 14
- 64
- 118
-
-
Do you define them in XML before the app is even built? Because in this case you may wrap them in a container like LinearLayout or RelativeLayout, grab an instance of this wrapper programmatically and get all of its views using a technique [like this](http://stackoverflow.com/a/7784472/1514026). – Dzhuneyt Jul 18 '13 at 13:39
-
can you give me some code for random textview..i have multiple textview and all quotes set in multiple textview. Please help me.. – Hitesh jadav Jul 19 '13 at 04:47
-
You should post some more code in your question if you want us to better assist you. – Dzhuneyt Jul 19 '13 at 08:46
-
-
http://stackoverflow.com/questions/17738896/android-multiple-textview-generate-random-textview-on-button-click – Hitesh jadav Jul 19 '13 at 09:29