这是将值放入ArrayList中的代码,我无法用“,”分割arraylist。有人可以帮我完成这项任务吗?
spinnerArrayList = new ArrayList<String>();
spinnerArrayList.add(menuFieldInstance.getFieldValues());
Log.i("spinnerArrayList",""+spinnerArrayList);
//for(int j=0;j<spinnerArrayList.size();j++)
//{
Log.i("spinnerArrayList after splitting ,",""+spinnerArrayList.get(0).split(","));
//}
这是拆分后的Spinner ArrayList和SpinnerArrayList的Logcat................。
02-10 22:00:48.285:I / spinnerArrayList(19378):[0100〜Avon&Somerset,0200〜Bedfordshire,0300〜Cambridgeshire,0400〜Cheshire,0500〜伦敦市,0600〜Cleveland,0700〜Cumbria,0800 〜德比郡,0900〜德文和康沃尔郡,1000〜多塞特郡,1100〜达勒姆,1200〜艾塞克斯,1300〜格罗斯特郡,1400〜大曼彻斯特,1500〜汉普郡,1600〜赫特福德郡,1700〜亨伯赛德,1800〜肯特郡,1900〜兰开夏郡, 2000〜Leicestershire,2100〜Linconshire,2200〜Merseyside,2300〜Metropolitan,2400〜Norfolk,2500〜Northamptonshire,2600〜Northumbria,2700〜North Yorkshire,2800〜Nottinghamshire,2900〜South Yorkshire,3000〜Staffordshire,3100〜Suffolk, 3200〜萨里(Surrey),3300〜萨塞克斯(Sussex),3400〜泰晤士河谷(Thames Valley),3500〜沃里克郡(Warwickshire),3600〜西默西亚(West Mercia),3700〜西米德兰兹(West Midlands),3800〜西约克郡(3900)〜威尔特郡(Wiltshire),4000〜戴菲德(4y) 〜南威尔士,4400〜皇家阿尔斯特,4500〜Strathclyde,4600〜中苏格兰,4700〜邓弗里斯和加洛韦,4800〜法夫,4900〜Grampian,5000〜Lothian and Borders,5100〜北苏格兰,5200〜Tayside,5300〜Gurnsey ,5400〜泽西州,5500〜曼岛,NO〜无波利ce Response,THAM〜THAMES VALLEY,WEST〜WEST MIDLANDS POLICE,5600〜Buckinghamshire]
02-10 22:00:48.285:分割后的I / spinnerArrayList,(19378):[Ljava.lang.String; @ 41b9a498
最佳答案
// try to print this way then you getting actual value at index becz your try to print String[] object rather each index value so do this way
spinnerArrayList = new ArrayList<String>();
spinnerArrayList.add("");
for (int i=0;i<spinnerArrayList.size();i++){
String[] splitedValue = spinnerArrayList.get(i).split(",");
for (int j=0;j<splitedValue.length;j++){
Log.i(i+" at ArrayIndex "+j+" at splitedIndex Value is >> ",splitedValue[j]);
String[] splitedValue1 = splitedValue[j].split("~");
if(splitedValue1.length==1){
continue;
}
for (int k=0;k<splitedValue1.length;k++){
Log.i(j+" at splitedIndex "+k+" at splited1Index Value is >> ",splitedValue1[k]);
}
}
}