I've been working on one recently app As a practice , It's about lost and found , One of the functions to be implemented is to read data from the cloud and display it in the app Of listview among , In fact, this function is quite common , But let's share it here , Mainly introduce the process and thinking of my solution .
I think we should pay attention to ! 1.Fragment How about findbyview? 2. use simpleAdapter Binding data 3. How to deal with the data from the cloud
4.listview How to show some ideas of data 5. Processing data list And map Application of 6.....
In this case, cloud data is used bmob Back end cloud as data storage , of bmob We will not elaborate on the use of , Self search learning for more information .
First, let's analyze the functional scenarios to be implemented , Now the cloud stores some data , We need to use app Read and display the data , So we need a layout, There's a listvie Use as presentation data , In addition, for data processing, we item custom style , We need one here list_item Used as a presentation of each item of data . We should also have a data sheet , Define the data types to be stored in the cloud, etc , With background data , There's also a container for displaying data , The next step is to connect cloud data with listview Connect , After all, the data is for users to see , So you need an adapter , Here we choose simpleAdapter.
first , Create layout .
This is the layout for each data presentation
contain listview Of layout
second , We need to create a data table
About creating data tables ,bmob Have corresponding development documents , The inherited parent class in the code above BmobObject It's also bmob Provided .
The above operations are relatively simple , Next, let's talk about data processing , After we create the data table , We can bmob Add data in white backend data , What's added is that the data is the data we want to read , Let's say you know a little bit bmob According to the development documents , Let's use the following method to get the data
This method is bmob Provided , Use it to get the data stored in the cloud , We found that the acquired data is stored in a list In the assembly , And according to list The generics of , The type of data stored is FoundData object , Based on this, if we want to use these data in the future, we need to check the obtained data list Processing .
Let's think about another problem before we deal with the data , That's the adapter , We know that adapter is a bridge between front-end display and back-end data , Choosing the right adapter is important , According to the data obtained, each item is an object , We can choose to use simpleAdapter To complete data adaptation .
After selecting the adapter, we will process the data , We use simpleAdapter Data adaptation , It depends on what kind of data the adapter needs , according to simpleAdapter The constructor of ,simpleAdapter The data object required in is a list aggregate , And this list Every object in the collection is another map aggregate , therefore , We need to convert the data we get into a list Set and every element is map aggregate , Because the data is also a list aggregate , But the elements in the collection are FoundData object , So we can use a map Collection to receive the resulting data
Now we have data list Value processing , We use for Loop traversal list Data for , Use the obtained data hashmap storage , So we get cloud data , And then hashmap Add to the list among , this list Each element in is a map aggregate .
And then we deal with the adapter , Populate data layout to adapter , And listview Set adapter .
Here , We successfully read the data stored in bmob Data on , this demo Mainly for bmob How to read and use the data stored on , Some of the processing methods involved can be referred to in some scenarios .
Because it's still in the advanced stage , If there is anything wrong with the above, please point out , Sorry for the inconvenience !