我应该创造这个:
listview.setAdapter(new yourAdapter(this, new String[] { "data1","data2" }));
但我不知道如何动态创建new String[]{...}
。
我有这段代码,我应该使用CitazioniOutput
数组:
String[] citazioni = getResources().getStringArray(R.array.citazioni);
List<String> CitazioniOutput = new ArrayList<String>();
for (String value : citazioni) {
CitazioniOutput.add(value);
}
我试过了:
listview.setAdapter(new yourAdapter(this, CitazioniOutput));
//and
ArrayAdapter<String> adapter= new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,CitazioniOutput);
listview.setAdapter(new yourAdapter(this, adapter));
但没有改变:它说
The constructor is undefined
如何将List<String>
转换为String[]
?
答案 0 :(得分:0)
您可以使用List课程中的方法:List.toArray(Object[]);
List<String> list = new List<String>();
String[] strings = new String[list.size()];
list.toArray(strings);