开发者

Populating ArrayAdapter - type String[]

I'm new to Java and Android development and i'm stucked while trying to populate an ArrayAdapter to creating a Li开发者_开发百科stView. 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 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜