com.github.kubatatami.judonetworking.AdapterCallback Maven / Gradle / Ivy
package com.github.kubatatami.judonetworking;
import android.widget.ArrayAdapter;
import java.util.List;
/**
* Created with IntelliJ IDEA.
* User: jbogacki
* Date: 14.03.2013
* Time: 13:56
*/
public class AdapterCallback extends Callback> {
private final ArrayAdapter adapter;
private boolean clear = true;
public AdapterCallback(ArrayAdapter adapter) {
this.adapter = adapter;
}
public AdapterCallback(ArrayAdapter adapter, boolean clear) {
this.adapter = adapter;
this.clear = clear;
}
public boolean filter(T result) {
return true;
}
@Override
public void onFinish(List result) {
if (clear) {
adapter.clear();
}
adapter.setNotifyOnChange(false);
for (T object : result) {
if (filter(object)) {
adapter.add(object);
}
}
adapter.notifyDataSetChanged();
}
}