Android 过滤列表视图

发布于 2024-12-06 13:15:51 字数 4029 浏览 1 评论 0原文

我需要一些帮助来解决我遇到的问题。我正在尝试获取我在应用程序中使用的列表视图的特定部分。这是我的列表视图中的内容:

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

,但它没有达到我想要的效果。

那么有什么建议如何做到这一点吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌能量女王 2024-12-13 13:15:51

过滤过程对列表中的每个对象调用 toString 方法进行匹配。因此,您的对象的 toString() 应该返回时间字符串。

您现在可以做的是将字段包装在一个类中,并重写其 toString(),您将在其中返回时间成员。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文