如何在Android应用程序中创建游标数据而不从数据库获取数据?

时间:2022-05-15 22:39:28

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应用程序中,我使用Sqlite数据库存储来自服务器的数据。我正在使用ContentProvider和ContentResolver从数据库访问数据,并使用CursorAdapter将数据绑定到ListView。一旦数据被插入到数据库中,CursorAdapter将被通知更新ListView。此外,每当我滚动ListView时,就会从数据库表中获得新的数据,并更新ListView。但是,当我到达表行末尾时,我需要直接从服务器获取数据,而不需要存储到数据库中并在ListView中更新数据。现在,当我使用接受游标数据的CursorAdapter时,我如何绑定一组不来自数据库的新数据呢?是否可以在不从数据库获取数据的情况下创建游标数据,并在ContentProvider中使用ChangeCursor()方法来更新ListView?如果没有,是否有其他方法可以达到同样的效果?

1 个解决方案

#1


9  

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

是否可以在不从数据库获取数据的情况下创建游标数据,并在ContentAdapter中使用ChangeCursor()方法来更新ListView?

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

是的,您可以使用MatrixCursor创建游标。如果您需要合并矩阵游标与数据库游标使用MergeCursor。

#1


9  

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

是否可以在不从数据库获取数据的情况下创建游标数据,并在ContentAdapter中使用ChangeCursor()方法来更新ListView?

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

是的,您可以使用MatrixCursor创建游标。如果您需要合并矩阵游标与数据库游标使用MergeCursor。