2014-03-31 45 views
0

重复的项目我从EXEL列表视图:如何在列表视图

try { 

     Workbook wb = WorkbookFactory.create(getAssets().open("bos.xls")); 
     Sheet sheet = wb.getSheetAt(0); 
     for(int i = 0; i < sheet.getPhysicalNumberOfRows(); i++) { 
     Row row = sheet.getRow(i); 
       Cell form1 = row.getCell(0); 
       Cell form2 = row.getCell(1); 
       Cell form3 = row.getCell(2); 

       IrrList = new ArrayList<HashMap<String, Object>>(); 

       HashMap<String, Object> hm; 

      hm = new HashMap<String, Object>(); 
      hm.put(Form1, form1.getStringCellValue()); 
      hm.put(Form2, form2.getStringCellValue()); 
      hm.put(Form3, form3.getStringCellValue()); 
      IrrList.add(hm); 

       SimpleAdapter adapter = new SimpleAdapter(this, IrrList, 
      R.layout.list_item, new String[] { Form1, Form2, Form3 }, 
            new int[] { R.id.text1, R.id.text2, R.id.text3 }); 
       listView.setAdapter(adapter); 
       listView.setTextFilterEnabled(true); 
     } 

     } catch(Exception ex) { 
      return; 
     } 

当我使用它,我在我的列表视图的一个值。
我该如何纠正它?

我尝试过添加此 “HashMap的HM;”:

for(int i1 = 0, l = IrrList.size(); i1 < l; i1++){ 
"I dont know what write here" 
    } 

回答

0

后的前试试这个..

用来初始化的ArrayListfor循环并设置listview adapterfor循环

IrrList = new ArrayList<HashMap<String, Object>>(); 
for(int i = 0; i < sheet.getPhysicalNumberOfRows(); i++) { 
    Row row = sheet.getRow(i); 
      Cell form1 = row.getCell(0); 
      Cell form2 = row.getCell(1); 
      Cell form3 = row.getCell(2);    

      HashMap<String, Object> hm; 

     hm = new HashMap<String, Object>(); 
     hm.put(Form1, form1.getStringCellValue()); 
     hm.put(Form2, form2.getStringCellValue()); 
     hm.put(Form3, form3.getStringCellValue()); 
     IrrList.add(hm);    
    } 
SimpleAdapter adapter = new SimpleAdapter(this, IrrList, 
     R.layout.list_item, new String[] { Form1, Form2, Form3 }, 
           new int[] { R.id.text1, R.id.text2, R.id.text3 }); 
      listView.setAdapter(adapter); 
      listView.setTextFilterEnabled(true); 
+0

感谢您的快速回复! =)我知道这很简单) – Ibir

+0

@ user3349698很高兴它帮助.happy编码。 – Hariharan