| This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. The article is believed to be still valid for the original topic scope. |
Contents |
The Widsets API has a Store class. This class must be used when you want to store and retrieve data in the mobile phone.
The Store class can persist the following classes: ByteArray, InputStream and Value. In this post we'll only see how to persist an instance of the Value class.
First of all, let's understand the Value class.
An instance of this class can be of the following types: boolean, int, long, String, Binary, Binding (a key-value pair) and List (a list of instances of the Value class).
In our example we'll use both Binding and List types to simulate a data table, with the structure and data showed below:
//The complete table is represented with a Value instance.
Value tbUsers = [];
//The two records.
Value user1 = ["name"=>"Marcos","age"=>;27];
Value user2 = ["name"=>"Fábio","age"=>;26];
//Now, we'll add each user into the table.
tbUsers.add(user1);
tbUsers.add(user2);
To get an instance of Store classe you must use the following code:
Store store = getStore();
Now, you can save the data into the table (tbUsers) using the below code:
store.put("tbUsers",tbUsers);
That's all!
If you want to retrieve all data from the table (tbUsers) you can use the below code:
Store store = getStore();
Value tableUsers = store.getValue("tbUsers");
for(int i = 0;i < tableUsers.size();i++){
printf(tableUsers.operator_get(i).operator_get("name"));
printf(tableUsers.operator_get(i).operator_get("age"));
}
The Store class is very easy to use, mainly for whom already know the FlashLite technology. The class StoredObject of the FlashLite API is very similiar to the Store class of Widsets API.
This post was originaly published on [Web Runtime Effort]
No related wiki articles found