我对java librairie OpenCSV有疑问。我没有成功读取我的CSV文件的所有行,我只读了第二行,我不知道为什么......
我的CSV文件:
"NumACLEB","Nom","Prenom","Niveau","Telephone","Portable","Rue","Code Postale","Ville","Activite","Adresse Mail","Cotisation Acleb","Cotisation Adherent"
"0","Pierre","Paul","Jacques","0585987445","0187458596","tests","92569","PARIS","POKER","test@test.fr","14","11"
"0","Julie","Julie","Beginner","0878589632","1445856996","test3","93857","PAris","POKER","foo@foo.fr","14","11"
我使用OpenCSV创建一个Android列表,只有“Julie”“Julie”这一行被添加3次......
try
{
CSVReader csvReader = new CSVReader(new FileReader(SettingsActivity.SaveFolder+"PDF/Liste_Membres.csv"),'\t');
//List<String[]> content = csvReader.readAll();
String[] row = csvReader.readNext();
while(row != null)
{
if(row[1]!="Nom")
{
map.put("viewname", row[1]+" "+row[2]);
map.put("viewDetails", "Ville : "+row[8]+" Cotisation ACLEB : "+row[11]+"€ Cotisation poker : "+row[12]+"€");
map.put("img", String.valueOf(R.drawable.aclebapc_logo));
listItem.add(map);
}else
{
map.put("viewname", "NOM Prenom");
map.put("viewDetails", "Ville - Cotisation ACLEB - Cotisation poker");
map.put("img", String.valueOf(R.drawable.aclebapc_logo));
listItem.add(map);
}
row = csvReader.readNext();
}
}catch(IOException ex)
{
Context context = getApplicationContext();
CharSequence text = "Erreur lors de l'ouverture du fichier CSV...";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
答案 0 :(得分:0)
我认为map
是某种词典?当您将值一遍又一遍地放在相同的键中时,它会覆盖之前的值。
我建议根据您尝试解决的问题采用不同的数据结构。
答案 1 :(得分:0)
Beautifulcoder击中了头部。您正在为地图中插入的每个值使用相同的键,因此您将覆盖所有内容,并且只会看到您在地图中放置的最后一个项目