2014-03-04 40 views
0

我希望我的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

@Merlevede我不是。花些时间阅读这个问题! – chuckfinley

回答

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

我不认为这是正确的,因为这显然缺乏onScroll监听器。 – chuckfinley

+1

看看这里http://stackoverflow.com/questions/16791100/detect-scroll-up-scroll-down-in-listview也许这个职位可以帮助你 – GhostDerfel

相关问题