如何从列表中删除“[]
How to remove ""[], from list
我有
["A","B","C","D"]
我想将它绑定到 android 微调器。我如何从 ["A","B","C","D"]
中删除 []"",以便只有字符会显示在微调器中。
sp1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String asd = "";
arrayList3.clear();
asd= arrayList2.get(position);
String[] items = asd.split(",");
List<String> list = Arrays.asList(items);
for(String item : list)
{
arrayList3.add(item);
}
ArrayAdapter<String> dataAdapter1 =
new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_spinner_item, arrayList3);
sp2.setAdapter(dataAdapter1);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
只需在您的代码中用 foreach 循环替换此代码
for(String item : list)
{
item = item.replace("[","");
item = item.replace("]","");
item = item.replace("\"","");
arrayList3.add(item);
}
我有
["A","B","C","D"]
我想将它绑定到 android 微调器。我如何从 ["A","B","C","D"]
中删除 []"",以便只有字符会显示在微调器中。
sp1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String asd = "";
arrayList3.clear();
asd= arrayList2.get(position);
String[] items = asd.split(",");
List<String> list = Arrays.asList(items);
for(String item : list)
{
arrayList3.add(item);
}
ArrayAdapter<String> dataAdapter1 =
new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_spinner_item, arrayList3);
sp2.setAdapter(dataAdapter1);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
只需在您的代码中用 foreach 循环替换此代码
for(String item : list)
{
item = item.replace("[","");
item = item.replace("]","");
item = item.replace("\"","");
arrayList3.add(item);
}