-1

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.

icodebuster
  • 8,890
  • 7
  • 62
  • 65

1 Answers1

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
  • i have multiple textview and it's defferent id.. – Hitesh jadav Jul 18 '13 at 13:10
  • 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
  • OK WordPress Developer.. – Hitesh jadav Jul 19 '13 at 09:28
  • http://stackoverflow.com/questions/17738896/android-multiple-textview-generate-random-textview-on-button-click – Hitesh jadav Jul 19 '13 at 09:29