How can I to add an array of `TextView` data into an existing text view?
How can I to add an array of TextView
data into an existing text view? I tried the following code:
TextView tvArrQuestion[]=(TextView) findViewById(R.id.Textparse);
...but I get this error:
Type mismatch: cannot convert from
TextView
toTextView[]
How can I resolve this?开发者_Python百科
You can do solve like ths:
first take a string append all the text arraydata to it.
String txt="";
for(int i=0;i<tvArrQuestion.length();i++)
{
txt=txt+tvArrQuestion[i].getText().toString();
}
than you can set it to textview
lets take textview tv so code is:
tv.setText(txt);
You cant give like that in ur code. Place ur code as:
TextView tvArrQuestion=(TextView) findViewById(R.id.Textparse);
and give
tvArrQuestion.setText(your array data);
Another Concept is below As this type u also add Text view
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(1);
TextView name[];
TextView website[];
TextView category[];
for (int i = 0; i < sitesList.getName().size(); i++) {
name[i] = new TextView(this);
name[i].setText("Name = "+sitesList.getName().get(i));
website[i] = new TextView(this);
website[i].setText("Website = "+sitesList.getWebsite().get(i));
category[i] = new TextView(this);
category[i].setText("Website Category = "+sitesList.getCategory().get(i));
layout.addView(name[i]);
layout.addView(website[i]);
layout.addView(category[i]);
}
Try this code using existing Layout
Textview name=(TextView)findViewById(R.id.textView1); String txt=""; for(int i=0;i
} name.setText(txt);
精彩评论