2011-11-03 11 views
3

我想列表項排序,我使用自定義列表視圖。在這我已經存儲在字符串數組中的項目。但在列出項目時,列表視圖顯示的是空項目而不是已排序的項目。但是,在調試時,字符串數組以有序格式存儲。如何解決它?如何在Android的自定義列表視圖列表中的項目進行排序?

+0

能否請您分享您的代碼? –

+0

我試圖爲列表項目排序這是正確的,或者您正試圖存儲產品正確 –

+0

我嘗試已存儲的列表項排序 –

回答

1

我所見過的代碼,我得到了下面的語句一些潛在的問題

HashMap<String, String> sampleObjectMap = new HashMap<String, String>(); 

      titles[i-1]=**sampleObjectMap.put("title", dh.val1(i-1))**; 
      persons[i-1]=**sampleObjectMap.put("person", dh.pers(i-1))**; 
      priorities[i-1]=**sampleObjectMap.put("priorty", setpriority(String.valueOf(dh.getpriority(i-1))))**; 
      dates[i-1]=**sampleObjectMap.put("dat", getDate(Long.valueOf(dh.time(i-1)),"dd/MM/yyyy"))**; 

這種大膽的聲明,將恢復以往任何映射的值與指定鍵或空,如果沒有這樣的映射。所以我假設在這種情況下以前沒有做過映射。所以請確保您數組填滿

+0

你是對的... –

4
/** 
    * need to sort the ArrayList based on Person’s firstName. 
    * Here inside the Collections.sort method we are 
    * implementing the Comparator interface and overriding the compare method. 
    */ 

     Collections.sort(employeeList, new Comparator(){ 

      public int compare(Object o1, Object o2) { 
       ContactInfo p1 = (ContactInfo) o1; 
       ContactInfo p2 = (ContactInfo) o2; 
       return p1.getEmployeeName().compareToIgnoreCase(p2.getEmployeeName()); 
      } 

     }); 





     this.fav_adapter = new FavoritesAdapter(this, R.layout.favorite_list_view, employeeList); 
     setListAdapter(this.fav_adapter); 





public class ContactInfo { 

    private String employeeLpn; 
    private String employeeName; 


/** 
    * Gets value for employeeLpn 
    * @return the employeeLpn 
    */ 
    public String getEmployeeLpn() { 
     return employeeLpn; 
    } 
    /** 
    * Sets the value for employeeLpn 
    * @param employeeLpn the employeeLpn to set 
    */ 
    public void setEmployeeLpn(String employeeLpn) { 
     this.employeeLpn = employeeLpn; 
    } 
    /** 
    * Gets value for employeeName 
    * @return the employeeName 
    */ 
    public String getEmployeeName() { 
     return employeeName; 
    } 
    /** 
    * Sets the value for employeeName 
    * @param employeeName the employeeName to set 
    */ 
    public void setEmployeeName(String employeeName) { 
     this.employeeName = employeeName; 
    } 

} 
+0

嗨排序,U可以共享的ContactInfo類碼? –

+0

Cooooooooooool .. –

+0

PattabiRaman我共享聯繫信息類 – jennifer

相關問題