Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create Cursor data without getting data from the DataBase in Android application?

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?

like image 794
Vivek Avatar asked Apr 07 '13 08:04

Vivek


People also ask

How can I store data on Android without database?

You could store it in a file. You could use a ContentProvider --> not recommended for temporary storage. You could use a SQLiteDB --> I know you said you do not want to use this.

Which method is used to get data from cursor?

The get() methods return the data from the column in the row which can then be used by the app. The Cursor class contains the following methods for retrieving data from a row: byte[] Cursor. getBlob(int columnIndex): Returns the value as a byte[]

How save and retrieve data from SQLite database in Android?

We can retrieve anything from database using an object of the Cursor class. We will call a method of this class called rawQuery and it will return a resultset with the cursor pointing to the table. We can move the cursor forward and retrieve the data. This method return the total number of columns of the table.


1 Answers

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.

like image 94
Leszek Avatar answered Oct 23 '22 17:10

Leszek