0

I would like my ListView to be updated with new entries on scroll up (i.e. the way Facebook do this). How can i achieve that?

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    // Inflate the layout
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View rowView = inflater.inflate(R.layout.list_single, parent, false);

    ImageView image = (ImageView) rowView.findViewById(R.id.picture);
    TextView firstline = (TextView) rowView.findViewById(R.id.firstline);
    TextView secondline = (TextView) rowView.findViewById(R.id.secondline);         

    // Get information about the report
    AnimalLocationLog current = objects.get(position);

    // Get all the important information
    String species = current.getSpecies();
    String sanitizedSpecies = MiscHelpers.sanitizeString(species);
    int reportId = objects.get(position).getTrackerId();

    // Construct the URL to the image
    String imageLocation = websiteUrl + sanitizedSpecies + separator + reportId + extension;

    // Display user report          
    downloader.download(imageLocation, image);          
    firstline.setText(species);
    secondline.setText("Spotted " + current.getDateTime().toString("yyyy-MM-dd H:m"));

    return rowView;
}
chuckfinley
  • 2,577
  • 10
  • 32
  • 42

2 Answers2

0

What you can do is getting track of your current item and if the item is the first or last (depends on what you want) then you will load more data and add that data to your list adapter.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
   //your code
   if(position==objects.size()){
        ArrayList<MyObject> newData = loadMoreData();
        objects.addAll(newData);
        myAdapter.notifyDataSetChanged();
   }
}
GhostDerfel
  • 1,533
  • 1
  • 11
  • 18
0

You can achieve this by using Endless Adapter the library is here and the tutorial regarding this can be found here and here.

NullPointerException
  • 3,978
  • 4
  • 34
  • 52