gpt4 book ai didi

java - 如何在动态textview中设置arraylist数据

转载 作者:行者123 更新时间:2023-12-02 03:24:25 24 4
gpt4 key购买 nike

每当我设置 rowTextView.setText("row value #"+ str); 然后 arraylist 最后一个值显示在那里。我的列表数据是 60,65,70,75,80 。仅显示最后一个值。我想要所有数据。我怎样才能实现这个???

 int size = al_getAllProductSize.size();

System.out.println("The size of array is: " + size);
for (int i = 0; i < size; i++) {


}

final int N = 5; // total number of textviews to add

final TextView[] myTextViews = new TextView[N]; // create an empty array;

for (int i = 0; i < N; i++) {
final TextView rowTextView = new TextView(MainActivity.this);

for (String str : al_getAllProductSize)
{

rowTextView.setText(" row value #" + str); // i want all value through loop

}

ll_textViewObj.addView(rowTextView);

// save a reference to the textview for later
myTextViews[i] = rowTextView;
}

最佳答案

如果您想要每个 TextView 中的每个字符串,您可以使用类似以下内容的内容:

for (int i = 0; i < N; i++) {
final TextView rowTextView = new TextView(MainActivity.this);

// getting respective string val from list
rowTextView.setText(" row value #" + al_getAllProductSize.get(i));

ll_textViewObj.addView(rowTextView);

// save a reference to the textview for later
myTextViews[i] = rowTextView;
}

关于java - 如何在动态textview中设置arraylist数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39159655/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com