Reputation: 301
I really apologize if this question has already been answered. I have not found any appropriate solution for the issue i am facing.
I have large an amount of data.
Which is i want to display in List ,this data contains images,urls,title,type and price.
List of the items can be more than 10,000
.
So if i am to implement Lazy Loading
i need all the urls and rest of the data so that i can load the images at run time .
But how do i load the data which contains the urls, titles, type and price list?.
Or can i load first the 20 records by lazy loading. If yes then how?
Please suggest if you have an better approach to getting this thing done.
Thanks in advance.
Upvotes: 2
Views: 1347
Reputation: 119
How i do this is that i load data (suppose 20 item) in ArrayList using AsyncTask then i set them to listview by using setAdapter and in getView method of ListAdapter as it reach to second last item i execute the AsyncTask again but this time instead of setAdapter i use adapter.notifyDataSetChanged(); how it should be is : getView method should be like this :
public View getView(int arg0, View arg1, ViewGroup arg2)
{
//your data inflater or set text...
if(arg0==yourList.size()-1)
{
new YourAsyncTask().execute());
}
}
AsyncTask Should Be Like this
//first initialize your list out of asynctask
ArrayList<String> yourList=new ArrayList<String>();
class YourAsyncTask extends AsyncTask(Void,Void,Void)
{
protected Void doInBackground(String ... arg0) {
// TODO Auto-generated method stub
//get your data and add to arraylist
yourlist.add(data);
}
protected void onPostExecute(Void result) {
if(yourlist.size<20){
listview.setAdapter(yourAdapter);
}
else
{
yourAdapter.notifyDataSetChanged();
}
}
}
Upvotes: 1
Reputation: 28093
Its entirely depends on how you architect the app.One approach I would preffer is to make one request to server which will return you urls,titles data in json format.
{
"dummy_info": "blah blah blah",
"data": [
{
"url": "http://www.google.com",
"title": "Sample",
"type": "Education",
"price": "50$"
},
{
"url": "http://www.google.com",
"title": "Sample",
"type": "Education",
"price": "50$"
}
]
}
Once you get that particular data then you can use Android SwipeRefreshLayout OR Lazy List loading implementation to fetch data in batches.
Upvotes: 0
Reputation: 1981
you can load 20 records at first and further more records when scrolling the ListView, by using ScrollListener
for your ListView
. check this answer
Upvotes: 1