Reputation:
TextView textView =(TextView)findViewById(R.id.text);
for(int i=1;i<6;i++)
{
textView.setText(i);
textView.setText("\n");
}
This is not printing
1
2
3
4
5
Please help me how to print the above output
Upvotes: 0
Views: 281
Reputation: 10959
try this
String value="";
for(int i=1;i<6;i++)
{
value = value + i + "\n";
}
textView.setText(value);
Upvotes: 0
Reputation: 5220
whenever you call setText
on a TextView
you change the entire text.
you should create your String
first and then set that as your TextView
's text.
String text = "";
for(int i=1;i<6;i++) {
text += i+"\n";
}
textView.setText(text)'
another solution is using append
instead of setText
for(int i=1;i<6;i++) {
textView.append(i+"\n");
}
Upvotes: 1
Reputation: 2793
I want from you in one comment to please show what it is printing right now ? and what you want to print ? if you have 6 textviews then just do this
tv1.setText(""+i+"");
tv1.setText(""+i+"");
tv1.setText(""+i+"");
tv1.setText(""+i+"");
tv1.setText(""+i+"");
Upvotes: 0