从List <string> </string>动态创建String []

时间:2014-01-22 14:27:31

标签: java android

我应该创造这个:

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[]

1 个答案:

答案 0 :(得分:0)

您可以使用List课程中的方法:List.toArray(Object[]);

    List<String> list = new List<String>();
    String[] strings = new String[list.size()];
    list.toArray(strings);