0

I would need to create a scrollview directly from Java code so I wrote this code (which I use in an AlertDialog).

TextView myTextView = new TextView(context);
myTextView.setText("Very long text" + longTextVariable);
ScrollView scroll = new ScrollView(context);
scroll.setBackgroundColor(android.R.color.transparent);
scroll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
builder.setView(myTextView);
builder.setView(scroll);

But it doesn't work because I do not see anything. To make you understand what I'm doing I tell you simply that I need to display text that very long without scroll view are "cut".

FD_
  • 12,947
  • 4
  • 35
  • 62
Mario G.
  • 393
  • 1
  • 3
  • 16
  • Check out this link: [http://stackoverflow.com/questions/1748977/making-textview-scrollable-in-android](http://stackoverflow.com/questions/1748977/making-textview-scrollable-in-android) – Andrew Dec 13 '13 at 19:47
  • Yes, it works but i want a really ScrollView – Mario G. Dec 13 '13 at 19:50

3 Answers3

1

At First need ti added TextView in scrollerView then Added this ScrollerView Alert

scroll.addView(myTextView);
builder.setView(scroll);

Thanks

Md Abdul Gafur
  • 6,213
  • 2
  • 27
  • 37
1

try this:

ScrollView scrlView = new ScrollView(this);
scrlView.setLayoutParams(new LayoutParams(
    ViewGroup.LayoutParams.MATCH_PARENT,
    ViewGroup.LayoutParams.WRAP_CONTENT));

TextView txt = new TextView(this);
txt.setText("test");
scrlView.addView(txt);

setContentView(scrlView);
TomTsagk
  • 1,474
  • 9
  • 23
0

You are setting the myTextView first as view in the builder and then replace it with scroll. That way you only have a empty scrollview.

You need to add the myTextView to the scrollview, then add the scrollview to the builder.

Peterdk
  • 15,625
  • 20
  • 101
  • 140