2

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.

usr30911
  • 2,731
  • 7
  • 26
  • 56
user3154663
  • 291
  • 1
  • 2
  • 18

3 Answers3

1

you can load 20 records at first and further more records when scrolling the ListView, by using ScrollListener for your ListView. check this answer

Community
  • 1
  • 1
Dharani Kumar
  • 1,981
  • 3
  • 13
  • 18
1

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();
                 }
      }
}       
Abhishek
  • 119
  • 7
0

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.

Vipul
  • 27,808
  • 7
  • 60
  • 75
  • thats what i am implementing. FIrst i want to get the data then load the image but the time scroll. But the if the data/list is too long then how it will work? – user3154663 May 14 '14 at 06:39