如何在向上滚动时更新列表视图?

时间:2014-03-04 19:33:21

标签: android listview

我希望我的ListView能够在向上滚动时更新新条目(即Facebook的方式)。我怎样才能做到这一点?

@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;
}

2 个答案:

答案 0 :(得分:0)

您可以做的是跟踪您当前的项目,如果该项目是第一个或最后一个(取决于您想要的),那么您将加载更多数据并将该数据添加到列表适配器。

@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();
   }
}

答案 1 :(得分:0)

您可以使用Endless Adapterhere来实现此目的,并且可以找到有关此内容的教程herehere