2

Hi i am not sure about implementing this particular scenario, i need some suggestions on it. i have a listview and i will be updating it by making a server call, if it is a small amount of data it will be quick, what if i have some 5000 records? do i need to load them in the memory or database and then query it and update listview? what is the best practice for this?

Suppose when i am downloading the data and suddenly there is a network drop? then how will i handle the data and updating the listview?

teekib
  • 2,821
  • 10
  • 39
  • 75

2 Answers2

1

I'm not sure about 5K records, but ListViews are known to handle well even large number of records using an effective recycling mechanism. See this thread for a detailed explanation.

Now, do yourself a favor and use Volley for your network resource loading. It does far better job in async loading of records into lists than most of us... In any case either the library you use or your own code must perform the resource loading/networking from a background thread.

You should also apply the ViewHolder pattern to your code. Using a ViewHolder is always a hood idea. it becomes crucial for a really large number of records. Please use it.
It should look like this

class ViewHolder {
    textView text1;
    Button button1;
}

class MyAdapter {
    public View getView(int position, View convertView, ViewGroup parent) {
         ViewHolder viewHolder = null;
         if (convertView==null){
              LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
              convertView = inflater.inflate(layoutResourceId, parent, false);
              viewHolder = new ViewHolderItem();
              viewHolder.text1 = (TextView) convertView.findViewById(R.id.text1);
              viewHolder.button1 = (Button) convertView.findViewById(R.id.button1);
              ..........
              convertView.setTag(viewHolder);
         }
         viewHolder = (ViewHolderItem) convertView.getTag();
         ObjectItem objectItem = data[position];
         ..........
    }
}


And, finally, if you really need partial loading together with a Load more functionality, please read: http://www.androidhive.info/2012/03/android-listview-with-load-more-button/


Community
  • 1
  • 1
Gilad Haimov
  • 5,767
  • 2
  • 26
  • 30
0

If you have 5000 records you don't should to get all records, you have to limit the query on the server so you do not send all records.

Then you can implement a "Show More or EndLess" to bring more data from the server when needed.

Example load more

joselufo
  • 3,393
  • 3
  • 23
  • 37
  • so first i should load them to my database and then update listview? – teekib Jul 04 '14 at 15:59
  • suppose if i updated my listview with 20 records and if there is sudden drop in network , how should i handle this scenario? – teekib Jul 04 '14 at 16:01
  • And what if i don't want to use any load more buttons or pagination, How should i go about this. – teekib Jul 04 '14 at 16:03
  • When you activate the "show more" check if there is internet. If there is no internet connection does not ask her to the server. If there is internet connection you ask the server. – joselufo Jul 04 '14 at 16:04
  • I think if you should implement paging in a scenario that if you have many records your application will be very slow. – joselufo Jul 04 '14 at 16:05