2014-03-31 73 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