È la prima volta che utilizzo il listener di onscroll. Il mio problema è come recuperare 20 nuove righe ogni volta che si scorre verso il basso?recupera solo 20 righe dal server con setOnScrollListener
Capisco quando farò scorrere verso il basso la vista della griglia questo codice verrà eseguito.
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
// TODO Auto-generated method stub
this.currentFirstVisibleItem = firstVisibleItem;
this.currentVisibleItemCount = visibleItemCount;
this.totalItem = totalItemCount;
if ((totalItemCount - visibleItemCount) <= (firstVisibleItem + 20)) {
// the below when executed will get all the rows ,I only need 20 rows
handler.execute().get();
}
}
questo è il mio codice
// the load more in the grid view, fetch new images.
mGridView.setOnScrollListener(new AbsListView.OnScrollListener() {
private int currentVisibleItemCount;
private int currentScrollState;
private int currentFirstVisibleItem;
private int totalItem;
private LinearLayout lBelow;
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
// TODO Auto-generated method stub
this.currentScrollState = scrollState;
this.isScrollCompleted();
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
// TODO Auto-generated method stub
this.currentFirstVisibleItem = firstVisibleItem;
this.currentVisibleItemCount = visibleItemCount;
this.totalItem = totalItemCount;
if ((totalItemCount - visibleItemCount) <= (firstVisibleItem + 20)) {
// load new 20 row but how to do that
}
}
private void isScrollCompleted() {
if (totalItem - currentFirstVisibleItem == currentVisibleItemCount
&& this.currentScrollState == SCROLL_STATE_IDLE) {
Log.d("a", "poooppii");
}
}
;
});
è qui che il collegamento avviene
protected void showList(){
try {
JSONObject jsonObj = new JSONObject(myJSON);
peoples = jsonObj.getJSONArray("result");
System.out.println("Length:"+peoples.length());
int J_length=peoples.length()-1;
jsonObj= peoples.getJSONObject(J_length);
Listitem = new ArrayList<Listitem>();
for (int i = 0; i < peoples.length(); i++) {
JSONObject c = peoples.getJSONObject(i);
String id = c.getString("id");
String url = c.getString("url");
int intid = 0;
try {
intid = Integer.parseInt(id.toString());
} catch (NumberFormatException nfe) {
System.out.println("Could not parse " + nfe);
}
Listitem.add(new Listitem(id, url));
System.out.println(Listitem);
}
//}
if (mListener != null)
mListener.myMethod(Listitem);
} catch (JSONException e) {
e.printStackTrace();
}
}
perché non si sta utilizzando l'adattatore invece di ascoltatori di scorrimento.Raccomando l'adattatore, perché qui questo problema può essere risolto molto facilmente e avrai anche un'esperienza migliore. – Neo
puoi per favore farmi vedere un esempio di come usarlo su un adattatore? – Moudiz
Ho pubblicato il mio codice di lavoro per la risoluzione dei problemi simile con l'aiuto dell'adattatore, spero che ti possa aiutare :) – Neo