我希望我的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;
}
答案 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)