1

Working on an Android app and I am getting back a one line response from a website similar to "Item 1", "Item 2", "Item 3" I need to convert the one line into a list to use in the array adapter for the simplelistitem. Any help would be appreciated, thanks. Here is the code.

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());
}
1
  • Be sure that your names array has different values. Check this in debug mode. if the names array have diffent values and adapter shows you the same value each time, you can say there is a problem here. But now, you must control the names array first. Commented Dec 14, 2012 at 7:13

1 Answer 1

2

Maybe this code will do for you:

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.