getLastVisiblePosition返回-1 [英] getLastVisiblePosition returning -1

查看:1429
本文介绍了getLastVisiblePosition返回-1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的的ListView (使用 CursorAdapte r)的一个问题。当我打电话 getListView()。getLastVisiblePosition()我收到 1 。这是一个问题,因为我的列表填充项。此外, getListView()。getFirstVisiblePosition()总是返回0,不管我在哪里滚动的名单上。任何想法?

I'm having a problem with my ListView (using CursorAdapter). When I call getListView().getLastVisiblePosition() I am receiving -1. This is a problem since my list is populated with items. Additionally, getListView().getFirstVisiblePosition() always returns 0, no matter where I am scrolled on the list. Any ideas?

它是与startManagingCursor

It has something to do with startManagingCursor

    @Override
    public void changeCursor(Cursor cursor) {
        super.changeCursor(cursor);
        MyActivity.this.mCursor = cursor;
        //startManagingCursor(MyActivity.this.mCursor);
    }

如果我注释掉startManagingCursor,一切工作正常。我也试图加入 stopManagingCursor()修改前光标,仍然有同样的问题。

If I comment out startManagingCursor, everything works fine. I've also tried adding stopManagingCursor() before changing the Cursor and still have the same problem.

推荐答案

这是因为你调用getListView()。getLastVisiblePosition()的那一刻ListView控件不呈现。您可以添加调用视图的消息队列是这样的:

This is because the moment you call getListView().getLastVisiblePosition() the listview is not rendered. You can add the call to the view's message queue like this:

listview.post(new Runnable() {
    public void run() {
        listview.getLastVisiblePosition();
    }
});

这篇关于getLastVisiblePosition返回-1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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