0
我有一个ListView与自定义适配器,我加载信息。我加载从DB retrived的所有数据到一个ArrayList(所有的数据是存在的),我复制我需要的数据,我向下滚动到另一ArrayList中,以显示它:ListView isScrollCompleted()问题
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.all_products);
footerView = ((LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer_view, null, false);
lv = (ListView) findViewById(R.id.lista);
lv.setOnScrollListener(new OnScrollListener() {
private void isScrollCompleted() {
if (lv.getHeight() == footerView.getBottom(){
update();
}
public void update(){
cargando=true;
lv.removeFooterView(footerView);
eventos=generarClaseEventos(null, eventosFULL,eventos);
adapter = new MyClassAdapter(AllProductsActivity.this,R.id.lista,eventos);
Comparator<Evento> comparador = new Comparator<Evento>() {
@Override //metodo que compara fechas
public int compare(Evento e1, Evento e2) {
if (e1 == null) return 1;
return e1.getFecha().compareTo(e2.getFecha());
}
};
int index= lv.getFirstVisiblePosition(); //almaceno el indice y la posición
View v = lv.getChildAt(0);
int top = (v == null) ? 0 : v.getTop();
adapter.sort(comparador);//llamo al metodo sort que ordena
lv.addFooterView(footerView);
lv.setAdapter(adapter);
adapter.notifyDataSetChanged();
lv.setSelectionFromTop(index, top); //restauro la posicion
cargando=false;
}
我得到的问题是,当我到达我的列表视图的底部时,我一直加载数据直到应用程序崩溃。我得到列表视图底部和footerview int的所有的时间,他们是一样的,就像我一直在向下滚动,但我不是。
这是怎么发生的?我正在通知我的适配器。