如何在滚动标志着ListView中读取项目? [英] How to mark item in listView readable while scrolling?

查看:162
本文介绍了如何在滚动标志着ListView中读取项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立我的第一个应用程序。这仅仅是一个通过短信(SMS)收到服务器的报警列表。只是有一个列表视图操作(点击上没有详细说明)。我想有可能标记项目通过阅读他们刚读。当我打开我的应用程序,我看到下令从旧到新的消息,我的ListView控件位置设置到ListView的底部。当我将向上滚动,显示的项目,我想标记为已读。

I am building my first application. It is just a list of server alarms received by a text message (SMS). There is just a list view action (no details on click). I want to be possible to mark items read just by reading them. When I open my app, I see messages ordered from old to new and my listView position is set to the bottom of the listView. When I will scroll up, the displayed items i want to mark as read.

和我这样做是这样的:

public class AlertsListFragment extends ListFragment {
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        // ...
        Cursor c = context.getContentResolver().query(uri, AlertsContract.PROJECTION, selection, selectionArgs, null);
        adapter = new AlertAdapter(context, R.layout.row, c, from, to, 0);
        setListAdapter(adapter);
        ListView listView = getListView();
        listView.setSelected(listView.getCount());

        lv.setOnScrollListener(new AbsListView.OnScrollListener() {
            public void onScrollStateChanged(AbsListView view, int scrollState) { }

            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
                for (int i = firstVisibleItem; i < firstVisibleItem + visibleItemCount; i++) {
                    Cursor cursor = (Cursor)view.getItemAtPosition(i);
                    long id = cursor.getLong(cursor.getColumnIndex(AlertsContract._ID));
                    String type = cursor.getString(cursor.getColumnIndex(AlertsContract.TYPE));
                    Log.d("VIEWED", "This is viewed "+ type + " id: " + id);

                    // here I can get the id and mark the item read
                }
            }
        });
    }
}

但我认为,这不是最好的解决办法。一个问题是,如果用户不打算滚动列表,没有项目被标记为观看甚至用户可以看到至少3 - 从列表4项

But I think, that this is not the best solution. One problem is that if the user is not going to scroll the list, no items are marked as viewed even the user could see at least 3 - 4 items from the list.

是否有一个ListView项无论如何,如显示或者类似的东西呢?会发生在每个ListView项获取到的ListView?

Is there any event for a listView item like "displayed" or something like this? Some event that will occur every time the listView item gets to the visible area of listView?

推荐答案

也许你应该尝试使用您的适配器 getView 方法。 (<一href=\"https://developer.android.com/reference/android/widget/Adapter.html#getView%28int,%20android.view.View,%20android.view.ViewGroup%29\"相对=nofollow>参考)

Maybe you should try to use your adapter's getView method. (Reference)

这就是所谓的每次当你的的ListView 尝试显示一个项目的时间。

It's called every time when your ListView tries to display an item.

但要小心,如果没有充分显示该项目它也叫,所以你应该再次检查这,也许在你的onScroll方法解决方案。

But be careful, it's also called when the item is not fully displayed, so you should check this again, perhaps with the solution in your onScroll method.

这篇关于如何在滚动标志着ListView中读取项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆