我在Sq lite数据库中将一些值存储为逗号分隔的字符串。现在我想从数据库到列表视图获取该值。但问题是,逗号分隔的字符串在列表视图中是直接可见的,我想拆分该字符串并在列表视图中显示。我很困惑,因为我使用数组列表将逗号与DB分开,我不知道如何在数组列表和显示列表视图中拆分该字符串?
how to split string from Arraylist by comma and get that stringd to listview.
答案 0 :(得分:1)
String temp = arrayValues.toString());
String qusChoice = temp.substring(1,temp.length() - 1);
String[] arrayList = qusChoice.split(",");
ArrayList choiceList = new ArrayList<String>();
for (int i = 0; i < arrayList.length; i++) {
choiceList.add(arrayList[i]);
}
ListView listChoice = (ListView)findViewById(R.id.list_choice);
adapter = new ChoiceAdapter(MainActivity.this,R.layout.custom_list,choiceList );
listChoice.setAdapter(adapter);