2011-09-25 31 views
0

我需要一點幫助,我有一個問題。我試圖獲取列表視圖的特定部分,我在我的應用程序中使用這裏是我在列表視圖中的內容:Android Filter ListView

public void onCreate(Bundle savedInstanceState){ 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.plovdiv); 
     setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 
     ListView schedule = (ListView) findViewById(R.id.pld_schedule); 
     String TIME = ""; 
     ArrayList <HashMap<String, Object>> items = new ArrayList<HashMap<String,Object>>(); 

     HashMap<String, Object> hm; hm = new HashMap<String, Object>(); 

     Calendar c = Calendar.getInstance(); 
     int hours = c.get(Calendar.HOUR); 
     int minutes = c.get(Calendar.MINUTE); 
     Log.i("Time","Hours : "+hours+" minutes : "+minutes); 

     hm = new HashMap<String, Object>(); 
     hm.put(TIME, "06:00"); 
     items.add(hm); 

     hm = new HashMap<String, Object>(); 
     hm.put(TIME, "06:30"); 
     items.add(hm); 

     hm = new HashMap<String, Object>(); 
     hm.put(TIME, "07:00"); 
     items.add(hm); 

     hm = new HashMap<String, Object>(); 
     hm.put(TIME, "07:30"); 
     items.add(hm); 

     hm = new HashMap<String, Object>(); 
     hm.put(TIME, "08:00"); 
     items.add(hm); 

     hm = new HashMap<String, Object>(); 
     hm.put(TIME, "09:15"); 
     items.add(hm); 

     hm = new HashMap<String, Object>(); 
     hm.put(TIME, "10:00"); 
     items.add(hm); 

     hm = new HashMap<String, Object>(); 
     hm.put(TIME, "10:45"); 
     items.add(hm); 

     hm = new HashMap<String, Object>(); 
     hm.put(TIME, "11:30"); 
     items.add(hm); 

     hm = new HashMap<String, Object>(); 
     hm.put(TIME, "12:15"); 
     items.add(hm); 

     hm = new HashMap<String, Object>(); 
     hm.put(TIME, "13:00"); 
     items.add(hm); 

     hm = new HashMap<String, Object>(); 
     hm.put(TIME, "13:45"); 
     items.add(hm); 

     hm = new HashMap<String, Object>(); 
     hm.put(TIME, "14:30"); 
     items.add(hm); 

     hm = new HashMap<String, Object>(); 
     hm.put(TIME, "15:15"); 
     items.add(hm); 

     hm = new HashMap<String, Object>(); 
     hm.put(TIME, "16:00"); 
     items.add(hm); 

     hm = new HashMap<String, Object>(); 
     hm.put(TIME, "16:30"); 
     items.add(hm); 

     hm = new HashMap<String, Object>(); 
     hm.put(TIME, "17:00"); 
     items.add(hm); 

     hm = new HashMap<String, Object>(); 
     hm.put(TIME, "17:30"); 
     items.add(hm); 

     hm = new HashMap<String, Object>(); 
     hm.put(TIME, "18:00"); 
     items.add(hm); 

     hm = new HashMap<String, Object>(); 
     hm.put(TIME, "18:40"); 
     items.add(hm); 

     hm = new HashMap<String, Object>(); 
     hm.put(TIME, "19:30"); 
     items.add(hm); 

     hm = new HashMap<String, Object>(); 
     hm.put(TIME, "20:00"); 
     items.add(hm); 

     hm = new HashMap<String, Object>(); 
     hm.put(TIME, "20:40"); 
     items.add(hm); 

     hm = new HashMap<String, Object>(); 
     hm.put(TIME, "21:40"); 
     items.add(hm); 

     hm = new HashMap<String, Object>(); 
     hm.put(TIME, "22:30"); 
     items.add(hm); 

     SimpleAdapter adapter = new SimpleAdapter( this, items, R.layout.main_listview, 
                new String[]{TIME}, new int[]{ R.id.text}); 


     schedule.setAdapter(adapter); 
     schedule.setChoiceMode(ListView.CHOICE_MODE_SINGLE); 

我想顯示列表視圖中的項目數量比當前時間更大。

例如這是10:30了,所以我想只顯示這是10:30在我的列表視圖中的值後事項:10:4511:30等我和

String time= hours+" : "+minutes; 
adapter.getFilter().filter(time); 

嘗試,但它沒有做我想做的事。

那麼有什麼建議如何做到這一點?

回答

0

過濾進程調用列表中每個對象上的toString方法進行匹配。所以你的對象的toString()應該返回時間字符串。

你現在可以做的是把你的領域包裝在一個班級中,並覆蓋它的toString(),你將返回時間成員。

+0

這個工作適合你嗎? – Ronnie

+0

:請幫我我也陷入了同樣的問題 –