Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8896291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:00:18+00:00 2026-06-15T00:00:18+00:00

In my application I am using pulltorefresh and ScrollListener concepts to show facebook feed

  • 0

In my application I am using pulltorefresh and ScrollListener concepts to show facebook feed data.As we can see in Android facebook app.

Here is code for pull to refresh

listView.setOnRefreshListener(new OnRefreshListener() {


            public void onRefresh() {
                // Your code to refresh the list contents goes here
                scroll=true;
                pic.clear();
                id.clear();
                name.clear();
                msg.clear();
                img.clear();
                profimg.clear();
                objid.clear();
                comment.clear();
                 previousTotal = 0;
                  loading = true;               
                listView.setAdapter(null);


                j=0;
                webserv="https://graph.facebook.com/me/home?access_token="+accesstoken;
                 doInBack dob=new doInBack();
                 dob.execute();  
//               doback(webserv);
                    Log.e("hi","doback called");

                // Make sure you call listView.onRefreshComplete()
                // when the loading is done. This can be done from here or any
                // other place, like on a broadcast receive from your loading
                // service or the onPostExecute of your AsyncTask.

                // For the sake of this sample, the code will pause here to
                // force a delay when invoking the refresh

            }
        });

And my scrolllistener class is here

    listView.setOnScrollListener(new  OnScrollListener() {

            private int threshold = 0;
//          
            public void onScrollStateChanged(AbsListView view, int scrollState) {
//                  
                  if (scrollState != 0) {  
                    isScrolling = true; 
                }
                else {   
                   isScrolling = false;  
                  adapter.notifyDataSetChanged();


                }  

            }


          public void onScroll(AbsListView view, int firstVisibleItem,int visibleItemCount, int totalItemCount) 
          {     

//           public void onScrollStateChanged(AbsListView view , int scrollState)
//           {
//                  if (scrollState != 0) {  
//                      listView.getAdapter().isScrolling = true; 
//                  }
//                  else {   
//                      listView.getAdapter().isScrolling = false;  
//                      listView.getAdapter().notifyDataSetChanged();  
//                  }  
//              }  
              // TODO Auto-generated method stub

              if (loading) {
                  if (totalItemCount > previousTotal) {
                      System.out.println(totalItemCount);
                      loading = false;
                      previousTotal = totalItemCount;
                  }
              } 
//                   int lastInScreen = firstVisibleItem + visibleItemCount; 
//              if (!loading && (totalItemCount - visibleItemCount) ==(firstVisibleItem + threshold)){
                   if (!loading && (firstVisibleItem + visibleItemCount) >= totalItemCount){
//                    if(((firstVisibleItem + visibleItemCount) == totalItemCount)){
//                   if (!(loading)  &&(totalItemCount - visibleItemCount) ==(firstVisibleItem + threshold)) {
//                clearAllResources(); 
                  scroll=false;
//                  if (!(loading)  &&(totalItemCount - visibleItemCount) == (firstVisibleItem + threshold)) {
                       Log.v("in gridview loading more","grid load");
//                      
                       doInBack dob=new doInBack();
                       dob.execute();  
//                       doback(webserv);
                    loading = true;
                   }
              }



      });

The issue i am getting is when I use async class for loading data
from facebookapi ,the scrollListener, totalItemcount value is becoming
2 when I pull my list to refresh.I didnt understand how it is
becoming 2 eventhough I clear all the list in my pullrefresh.

The important thing is I am not getting this issue at all when I use
normal method instead of this Async class.

 Here I am providing both my doback() and async class,I think there is something going wrong when I use Async class.

Here is my Async class

     class doInBack extends AsyncTask<URL, Integer, Long>
    {


        @Override
        protected Long doInBackground(URL... arg0) {


//          dialog=MyProgressDialog.show(Wall.this, null,null);

            Log.e("hi","doback parsing");
//          int count=0;

            currentweb= webserv;
            try
            {   
//              if(urlval>0){
                    wallres=UrltoValue.getValuefromUrl(webserv);
                    Log.e("wallrespages",wallres);
//              }
//              else{
//              wallres=UrltoValue.getValuefromUrl(web+accesstoken);
//              Log.e("wallreshome",wallres);
//              }
                JSONObject jobj1=new JSONObject(wallres);

                JSONObject jobj2=jobj1.getJSONObject("paging");
                webserv= jobj2.getString( "next");

                 jsonArray = jobj1.getJSONArray("data");




                 for(int i=0;i<jsonArray.length();i++){

                     jsonObject = jsonArray.getJSONObject(i);





                    if(jsonObject.has("message")||jsonObject.has("picture")) {

                        try{


//                        msg[j]=jsonObject.getString("message");
                            if(jsonObject.has("message"))
                            {

                                msg.add(jsonObject.getString("message"));   
                            }
                            else{
                                msg.add("");    
                            }
                        }
                        catch(Exception e){
                            e.printStackTrace();
                        }

                        try{

//                            msg[j]=jsonObject.getString("message");
                                if(jsonObject.has("picture"))
                                {
                                    String firstpicture=jsonObject.getString("picture");
                                    String secondpicture=firstpicture.replaceAll("_s.jpg", "_n.jpg");
                                     Log.e("picurl",secondpicture);
                                     pic.add(secondpicture);

                                }
                                else{
                                    pic.add("");
                                }
                            }
                            catch(Exception e){
                                e.printStackTrace();
                            }

                        objid.add(jsonObject.getString("id"));

                          JSONObject jobj=jsonObject.getJSONObject("from");
                           name.add(jobj.getString("name"));
                           id.add(jobj.getString("id"));
//                         Log.e("msg",msg);
//                            
//                         Log.e("name",name[j]);
//                         Log.e("id",id[j]);
                           profimg.add("http://graph.facebook.com/"+id.get(j)+"/picture?type=square");

                           JSONObject commentjobj=jsonObject.getJSONObject("comments");
                            comment.add(commentjobj.getString("count"));
                            weburl.add( currentweb);

                           Log.e("comment", comment.get(j));
//                         bitmap[j]= getBitmapFromURL(profimg[j]);
//                         profimg1.setImageBitmap(bitmap[j]);
//                         imageLoader.DisplayImage( profimg[j].replace(" ", "%20"), profimg1) ;
//                         System.out.println( bitmap[j]);
                           j++;
//                          f=j;
                    }
                    }


//                if(jsonObject.getString("message")!=""){
//                    msg[i]=jsonObject.getString("message");
//                     
//                    JSONObject jobj=jsonObject.getJSONObject("from");
//                     name[i]= jobj.getString("name");
//                     id[i]=jobj.getString("id");
//                     Log.e("msg",msg[i]);
//                     Log.e("name",name[i]);
//                     Log.e("id",id[i]);
//                     }
//                       
//                   }





            }

            catch(Exception e)
            {
                e.printStackTrace();
            }

            return null;
        }

        protected void onPostExecute(Long result) { 

            try
            {  
                System.out.println(scroll);
                if(scroll){
//                   listView.addFooterView(footerView);
                 adapter=new MySimpleArrayAdapter(Wall.this,R.layout.wall,pic,name,msg,id,profimg,bitmap,comment,objid,weburl);
                listView.setAdapter(adapter);

//              dialog.dismiss();
                listView.postDelayed(new Runnable() {

//                  @Override
                    public void run() {

                        listView.onRefreshComplete();
                    }
                }, 2000);

                }


         else{
//           adapter=new MySimpleArrayAdapter(Wall.this,R.layout.wall,pic,name,msg,id,profimg,bitmap,comment,objid,weburl);
             adapter.notifyDataSetChanged();
             listView.postDelayed(new Runnable() {

//                  @Override
                    public void run() {

                        listView.onRefreshComplete();
                    }
                }, 2000);

            }
            }

            catch(Exception e)
            {
                e.printStackTrace();
//              dialog.dismiss();
            }

    }

    }

And my normal method is

 public void doback(String url) 
        {

            currentweb=url;


//              dialog=MyProgressDialog.show(Wall.this, null,null);

                Log.e("hi","doback parsing");
//              int count=0;

                try
                {   
//                  if(urlval>0){
                        wallres=UrltoValue.getValuefromUrl(currentweb);
                        Log.e("wallrespages",wallres);
//                  }
//                  else{
//                  wallres=UrltoValue.getValuefromUrl(web+accesstoken);
//                  Log.e("wallreshome",wallres);
//                  }
                    JSONObject jobj1=new JSONObject(wallres);

                    JSONObject jobj2=jobj1.getJSONObject("paging");
                    webserv= jobj2.getString( "next");

                     jsonArray = jobj1.getJSONArray("data");
//                   
//                    for(int k=0;k<jsonArray.length();k++){
//                       
//                       jsonObject = jsonArray.getJSONObject(k);
//                       if(jsonObject.has("message")||jsonObject.has("picture")) {
//                              count++;
//                       }
//                    }
//                    jsonObject=null;

//                   msg=new String[count];
//                   name=new String[count];
//                   id=new String[count];
//                   profimg=new String[count];
//                   bitmap=new Bitmap[count];
//                   pic=new String[count];

                     for(int i=0;i<jsonArray.length();i++){

                         jsonObject = jsonArray.getJSONObject(i);





                        if(jsonObject.has("message")||jsonObject.has("picture")) {

                            try{


//                            msg[j]=jsonObject.getString("message");
                                if(jsonObject.has("message"))
                                {

                                    msg.add(jsonObject.getString("message"));   
                                }
                                else{
                                    msg.add("");    
                                }
                            }
                            catch(Exception e){
                                e.printStackTrace();
                            }

                            try{

//                                msg[j]=jsonObject.getString("message");
                                    if(jsonObject.has("picture"))
                                    {
                                        String firstpicture=jsonObject.getString("picture");
                                        String secondpicture=firstpicture.replaceAll("_s.jpg", "_n.jpg");
                                         Log.e("picurl",secondpicture);
                                         pic.add(secondpicture);

                                    }
                                    else{
                                        pic.add("");
                                    }
                                }
                                catch(Exception e){
                                    e.printStackTrace();
                                }

                            objid.add(jsonObject.getString("id"));

                              JSONObject jobj=jsonObject.getJSONObject("from");
                               name.add(jobj.getString("name"));
                               id.add(jobj.getString("id"));
//                             Log.e("msg",msg);
//                                
//                             Log.e("name",name[j]);
//                             Log.e("id",id[j]);
                               profimg.add("http://graph.facebook.com/"+id.get(j)+"/picture?type=square");

                               JSONObject commentjobj=jsonObject.getJSONObject("comments");
                                comment.add(commentjobj.getString("count"));
                                weburl.add(url);

                               Log.e("comment", comment.get(j));
//                             bitmap[j]= getBitmapFromURL(profimg[j]);
//                             profimg1.setImageBitmap(bitmap[j]);
//                             imageLoader.DisplayImage( profimg[j].replace(" ", "%20"), profimg1) ;
//                             System.out.println( bitmap[j]);
                               j++;
//                              f=j;
                        }
                        }

//                    if(jsonObject.getString("message")!=""){
//                        msg[i]=jsonObject.getString("message");
//                         
//                        JSONObject jobj=jsonObject.getJSONObject("from");
//                         name[i]= jobj.getString("name");
//                         id[i]=jobj.getString("id");
//                         Log.e("msg",msg[i]);
//                         Log.e("name",name[i]);
//                         Log.e("id",id[i]);
//                         }
//                           
//                       }





                }

                catch(Exception e)
                {
                    e.printStackTrace();
                }





                    try
                    {  
                        System.out.println(scroll);
                        if(scroll){

                         adapter=new MySimpleArrayAdapter(Wall.this,R.layout.wall,pic,name,msg,id,profimg,bitmap,comment,objid,weburl);
                        listView.setAdapter(adapter);
                          listView.postDelayed(new Runnable() {

//                              @Override
                                public void run() {

                                    listView.onRefreshComplete();
                                }
                            }, 2000);

                        dialog.dismiss();
                        }

                 else{
//                   adapter=new MySimpleArrayAdapter(Wall.this,R.layout.wall,pic,name,msg,id,profimg,bitmap,comment,objid,weburl);
                     adapter.notifyDataSetChanged();
                      listView.postDelayed(new Runnable() {

//                          @Override
                            public void run() {

                                listView.onRefreshComplete();
                            }
                        }, 2000);
                    }


                    }



                    catch(Exception e)
                    {
                        e.printStackTrace();
//                      dialog.dismiss();
                    }

            }   
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T00:00:20+00:00Added an answer on June 15, 2026 at 12:00 am

    There’s a couple of factors here, I think. First, I’m not sure what Pull to refresh library or widget you’re using, but if it includes header and footer views, your count might be off by the footer and header views. I think that’s why your scrollview gets called with 2.

    I suggest that you clear your adapter until the refresh operation completes, that might make everything just work (because the scroll listener won’t be called for an empty list).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building an application using gevent. My app is getting rather big now as
I wrote an application using the Android 2.2 SDK (API level 8). It is
I've created Android application using Maps API V3 on WebView and local HTML files(contained
I am making application using phonegap in android. I am using cordova 1.6.1 I
I am developing application using phonegap in eclipse for android .I have created folder
I'm creating a application using entity framework code-first and i'm facing some problems with
we are creating an application using HTML5 for Iphone, IPAD and Android. Now the
Our application (using a SQL Server 2008 R2 back-end) stores data about remote hardware
I have a Php application using stream_socket_client(), to get data through tcp from a
My application using a GeoCoder keeps returning the string to true. here is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.