How to show list of string in TextView on Android
You need to loop through all "Star" elements and build the string yourself. You should have something like this:
String concatenatedStarNames = "";
List<Star> stars = model.get(position).getStars(); // I assume the return value is a list of type "Star"!
for (int i = 0; i < stars.size(); i++) {
concatenatedStarNames += stars.get(i).getName();
if (i < stars.size() - 1) concatenatedStarNames += ", ";
}
And then you set the text of the text view to concatenatedStarNames
.
How to set ListString in textView on android
Use android.text.TextUtils.join()
holder.txtState.setText(TextUtils.join(", ", list.get(position).getDesc()));
Display list of text using 1 textview
replace
ans.setText("The result is : " + userInput + " * " + i + " = " + result);
with
ans.append("The result is : " + userInput + " * " + i + " = " + result + "\n");
and your problem is solved
How to display multiline from array list in single TextView?
Use a StringBuilder to make your array 1 String and append linebreaks in between the individual Strings like this:
StringBuilder builder = new StringBuilder();
for (String details : list2) {
builder.append(details + "\n");
}
custName.setText(builder.toString());
How to show items in list of strings in textviews dynamically
SOLVED MY QUESTION.
The actual problem is here,
tv.setText(w.set1);
but when i changed it to,
String set1 = w.set1.get(i);
tv.setText(set1);
the problem solved.
How to display Strings from ArrayList in TextView
Edit based on new information:
To display the texts from all the toggles that are currently ON in your TextView
I suggest that you create a
private ArrayList<String> mActiveToggles = new ArrayList<String>();
Whenever a toggle button is set to ON, you add the label of that toggle button to the list. Whenever a toggle button is set to OFF, you remove the label from the list.
if(on) {
if (b.equals("0")) return; // Don't really know why you need this one...
// If the button is ON, add its text label to the list.
mActiveToggles.add(btn.getText());
} else {
// If button is OFF, remove its text label from the list.
mActiveToggles.remove(btn.getText());
}
To update your TextView
simple iterate over the items in the list and add them to the TextView
(with an appropriate separator). Something like this:
StringBuilder allLabels = new StringBuilder();
for(String s : mActiveToggles) {
if(allLabels.length() > 0) {
allLabels.append(" "); // some divider between the different texts
}
allLabels.append(s);
}
display.setText(allLabels.toString());
If you really do need the content of your TextView
to be persistently stored, iterate over the list items and concatenate them and then store them to your SharedPreferences
object. Restoring them from storage would simply be the reverse operation of splitting the String and populating the list. Based on the code that you've provided I don't see a need for this, but there could of course be more to it than what you've posted here.
Android viewing an arraylist in text view
Please keep in mind that it is not the best way to show list items in a TextView
. You can do this using a ListView
. Anyhow, see pseudo code below (didn't test that in Eclipse, however, it should show how it is basically going to work):
public class YourActivity extends Activity {
Vector<String> choices = new Vector<String>();
public void onCreate(Bundle ....) {
(Button) myButton = (Button) findViewById(R.id.button);
myButton.setOnClickListener(new OnClickListener() {
@Override
public boolean button.onClick() {
addString();
TextView textView = (TextView) findViewById(R.id.text_view);
String listRepresentation = "";
for (String choice : choices)
if ("".equals(listRepresentation))
listRepresentation = choice; else
listRepresentation = ", " +choice;
textView.setText(listRepresentation );
}
});
}
public void addString(View view)
{
EditText editText = (EditText) findViewById(R.id.edit_choice);
String message = editText.getText().toString();
choices.add(message);
}
}
So simply assign an OnClickListener
to your button that does what you need.
How to display ArrayList in TextView?
In your adapter's getView() you have setting the whole question list in text view by this line of code -
holder.questionTextView.setText("Q " + position + ": \t" + quesList);
In stead you have only to show one questoion as -
holder.questionTextView.setText("Q " + position + ": \t" + quesList.get(position));
Thanks.
Related Topics
Download a File Programmatically on Android
How to Display an Image in Full Screen on Click in the Imageview
How to Connect Localhost in the Android Emulator
How to Set Transparency of a Background Image Android Xml File
Could Not Connect to React Native Development Server on Android
Android Push Notifications Not Being Received When App Closed
How to Use Adb With Emulator Like Memu/Bluestacks/Nox App Player
Retrofit @Body With @Multipart Having Issue
Constraint Layout Scroll to Bottom With Keypad Open
Passing an Arraylist of Objects to the New Activity
How to Implement My Custom Toolbar in My Fragment
I Want to Change Actionbar Icon Size
Webview and Html5 ≪Video≫