1

在一个 Android 应用程序上工作,我从一个类似于“Item 1”、“Item 2”、“Item 3”的网站得到一个单行响应,我需要将一行转换为一个列表以在数组适配器中使用最简单的项目。任何帮助将不胜感激,谢谢。这是代码。

try {
    BufferedReader reader = new BufferedReader(new InputStreamReader(webs,"iso-8859-1"),8);
    String[] names = new String[] {reader.readLine()};
    webs.close();
    setListAdapter (new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, names));
} catch(Exception e) {
    Log.e("Log_tag", "Error converting results"+e.toString());
}
4

1 回答 1

2

也许这段代码会为你做:

String namesString = reader.readLine();
String [] names = namesString.split(", ");
//optional if you wish to remove the quotes
for (int i = 0; i < names.length; i++) {
   names[i] = names[i].substr(1, names[i].length() - 1);
}
//use it as you wish
于 2012-12-14T07:10:11.113 回答