填充ArrayAdapter - 类型为String [] [英] Populating ArrayAdapter - type String[]
本文介绍了填充ArrayAdapter - 类型为String []的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是新来的Java和Android的发展,我stucked尝试来填充ArrayAdapter创造一个ListView。下面的code完美的作品:
I'm new to Java and Android development and i'm stucked while trying to populate an ArrayAdapter to creating a ListView. The code below works perfectly:
String name[] = {"a","b","c",
"d","e"};
this.setListAdapter(new ArrayAdapter<String>(this,
R.layout.row, R.id.label,
name));
但我根本想不出应该怎么填写名称
与为
循环。所有建议都欢迎。
But I simply can't figure out how I should populate name
with a for
loop. All suggestions are welcome.
推荐答案
ArrayAdapter
也有一个构造函数一个列表&LT;弦乐&GT;
,所以你可以做
ArrayAdapter
also has a constructor that takes a List<String>
, so you can just do
List<String> name = new ArrayList<String>();
for (... ) {
name.add(.... );
}
this.setListAdapter(new ArrayAdapter<String>(this,
R.layout.row, R.id.label,
name));
否则,它只是归结为填充数组数据。
Otherwise it just boils down to populating an array with data.
这篇关于填充ArrayAdapter - 类型为String []的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文