2014-03-04 62 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

相關問題