开发者

Android Filter ListView

开发者 https://www.devze.com 2023-04-08 02:31 出处:网络
I need a little help with a problem that I have.I\'m trying to get a specific part of a list view which I am using in my application.Here is what I have in my list view :

I need a little help with a problem that I have.I'm trying to get a specific part of a list view which I am using in my application.Here is what I have in my list view :

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);

I want to show the items in list view which are bigger as number from the current time.

example It's 10:30 now, so I want to show only the items which are after 10:30 as a value in my list view : 10:45 , 11:30 and etc. I've tried with

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

,but it's not doing what I want.

So any suggestions how to do that?


The filtering process calls the toString method on each object in the list for matching. So your object's toString() should be returning the time string.

What you can do now is wrap your fields in a class and override its toString() where you'll return the time member.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号