Its the first time I am using onscroll listener. My problem is how to fetch 20 new rows every time I scroll down ?.
I understand when I scroll down the grid view this code will be executed.
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();
            }
        }
this is my code
// 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");
        }
    }
    ;
});
this is where the connection happens
 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();
        }
    }
 
     
     
    