如何在没有从Android应用程序数据库中获取的数据创建游标数据?数据、游标、数据库中、应用程序

2023-09-07 16:20:57 作者:笑谈风华

在我的Andr​​oid应用程序,我使用的SQLite数据库存储从服务器的数据。我使用的ContentProvider和ContentResolver的从数据库中访问数据和使用的CursorAdapter将数据绑定到ListView。一旦将数据插入到数据库中,CursorAdapter的将被通知来更新ListView控件。此外,每当我滚动的ListView,我从数据库表中获取新的数据和ListView将被更新。但是,一旦我达到表行的末尾,我需要将数据直接从服务器,而无需存储到数据库中提取,并在ListView更新。现在,当我使用的CursorAdapter它接受光标数据,我怎么可以绑定一个新的组数据,它不会从数据库里?是否有可能不从数据库中获取的数据创建光标数据,并使用ChangeCursor()方法在ContentProvider更新的ListView?如果没有,是否有任何其他的方法来达到同样的?

解决方案   

时有可能不从获取的数据创建数据光标  数据库和ContentAdapter使用ChangeCursor()方法来更新  ListView的?

是的,你可以使用 MatrixCursor 创建光标。如果你必须与数据库游标使用 MergeCursor 合并MatrixCursor。

In my Android application, I am using Sqlite DataBase to store the data from the server. I am using ContentProvider and ContentResolver to access the data from the DataBase and using CursorAdapter to bind the data to the ListView. As soon the data is inserted into the DataBase, CursorAdapter will be notified to update the ListView. Also, whenever I scroll the ListView, I get new data from the DataBase table and ListView will be updated. But once I reaches to the end of the table row, I need to fetch the data directly from the server without storing into the DataBase and update it in the ListView. Now as I am using CursorAdapter which accepts Cursor data, how can I bind a new set of data which is not coming from the DataBase? Is is possible to create Cursor data without getting data from the DataBase and use ChangeCursor() method in the ContentProvider to update the ListView? If not, is there any other method to achieve the same?

解决方案 Android应用开发教程之八 应用程序数据库

Is is possible to create Cursor data without getting data from the DataBase and use ChangeCursor() method in the ContentAdapter to update the ListView?

Yes, you can create cursor using MatrixCursor. If you will have to merge MatrixCursor with database Cursor use MergeCursor.