你能帮我把下面的字符串插入TextView或ListView吗?
["星期一:1:30-3:30","星期二:1:30-3:30","星期三:1:30- 下午3:30,8:30 - 11:00","周四:1:30 - 3:30 PM,8:30 - 11:00 PM","周五:下午1:30 - 3:30,晚上8:30-11:00","周六:1:30-3:30 下午8:30-11:00","周日:关闭"]
我需要它显示如下,每行一个:
星期一:下午1:30 - 3:30星期二:下午1:30 - 3:30星期三:1:30 - 下午3:30,晚上8:30 - 晚上11:00周四:1:30 - 3:30,8:30 - 11:00 PM
谢谢!
答案 0 :(得分:1)
如果你想让它在一个TextView中很简单;
List<String> myList = getMyListFromJSON();
StringBuilder sb = new StringBuilder();
for(int i = 0; i < myList.size(); i++){
if(i+1 != myList.size()){
sb.append(myList(i));
sb.append("\n");
} else {
sb.append(myList(i));
}
myTextView.setText(sb.toString());
答案 1 :(得分:0)
String input = yourInputStringAbove;
// remove square brackets
input = input.substring(1, input.length() - 1);
// split each item by quotes and commas
String[] subset = input.split("\",\"");
// create output string (for single TextView, delete if using ListView)
String output = "";
for (String string : subset) {
// strip quotation marks
string = string.replace("\"", "");
// add the string to the output
output += string + "\n"; // (for single TextView, delete if using ListView)
}
// For a TextView
TextView textView = (TextView) findViewById(R.id.your_text_view);
textView.setText(output);
// For a ListView
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getContext(), R.layout.your_text_view_layout, subset);
ListView listView = (ListView) findViewById(R.id.your_list_view);
listView.setAdapter(adapter);