我不知道你是怎么做的,但听起来你完全可以使用回调来实现它。
1)创建一个这样的界面:
public interface OnDownloadProgressChangeListener{
public void onProgress(int progress);
}
2)将此添加到您的 MovieData 对象:
// We use an ArrayList because you could need to listen to more than one event. If you are totally sure you won't need more than one listener, just change this with one listener
private ArrayList<OnDownloadProgressChangeListener> listeners = new ArrayList<OnDownloadProgressChangeListener>();
public void addDownloadProgressChangeListener(OnDownloadProgressChangeListener listener){
listeners.add(listener);
}
public void clearDownloadProgerssChangeListeners(){
listeners.clear();
}
//Add any handlers you need for your listener array.
// ALWAYS use this method to change progress value.
public void modifyProgress(int howMuch){
progress+=howMuch;
for (OnDownloadProgressChangeListener listener : listeners)
listener.onProgress(progress);
}
3)覆盖您的自定义适配器添加方法
@Override
public void add(final MovieData item){
item.addDownloadProgressChangeListener(new OnDownloadProgressChangeListener(){
public void onProgress(final int progress){
// Add your logic here
if (progress == 100){
item.update();
}
}
});
super.add(item);
}
4) 每当修改项目时,请调用notifyDataSetChanged()
您的适配器。您甚至可以在实现中的super.add(item)
行之后添加它add
,但是如果您要添加很多项目,这将非常低效:先添加它们然后通知更改。