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 9148889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:23:41+00:00 2026-06-17T11:23:41+00:00

Every time I pull to refresh (using chrisbanes library), my ListView gets all the

  • 0

Every time I pull to refresh (using chrisbanes library), my ListView gets all the “new” data appended to the end of the old data, instead of replacing it. I already checked my Json parser, which returns my ArrayList, and it’s definitely NOT that I’m accidentally doubling up in the list itself.

I’ve tried all sorts of “notifyDataSetChanged()”‘s and “.invalidate()”‘s and I just cannot seem to convince my ListView to fully repopulate itself. It works correctly on orientation-shift, which I realize is a clue, but I can’t seem to figure out what is different in that case.

Code below, thanks for any tips!

public class VoicemailsPME extends Activity{

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.voicemails_pme);

    listView = (PullToRefreshListView) findViewById(R.id.pulllist);

    final String username = getIntent().getExtras().getString("username"); 
    final String password = getIntent().getExtras().getString("password");
    mailboxId = getIntent().getExtras().getString("mailboxId");

    m_voicemails = new ArrayList<Voicemail>();

    mHandlerFirst.post(new Runnable() {

        @Override
        public void run() {
            CheckConnectionTask CCT = new CheckConnectionTask(VoicemailsPME.this);
            CCT.execute(username, password);
            firstTime = false;
        }
    });

    listView.setOnRefreshListener(new OnRefreshListener<ListView>() {

        @Override
        public void onRefresh(PullToRefreshBase<ListView> lv) {
            lv.invalidate();
            mHandler.post(new Runnable() {                  
                @Override
                public void run() {
                    CheckConnectionTask CCT = new CheckConnectionTask(VoicemailsPME.this);
                    CCT.execute(username, password);
                }
            });
        }
    });

    this.m_adapter = new OrderAdapter(this, R.layout.voicemails_pme_row, m_voicemails);
    listView.setAdapter(m_adapter);
}

private Runnable returnRes = new Runnable() {

    @Override
    public void run() {
        if(m_voicemails != null && m_voicemails.size() > 0){
            for(int i=0;i<m_voicemails.size();i++)
                m_adapter.add(m_voicemails.get(i));
        }
    }
};

private void getVoicemails(){
    try{
        //Log.d("Data right before Json Parse", data);
        Json jsonParser = new Json(data);

        m_voicemails = jsonParser.getVoicemailsPME();
    } catch (Exception e) {
        Log.e("BACKGROUND_PROC", e.getMessage());
    }
    runOnUiThread(returnRes);
}

private class OrderAdapter extends ArrayAdapter<Voicemail> {

    private ArrayList<Voicemail> items;

    public OrderAdapter(Context context, int textViewResourceId, ArrayList<Voicemail> items) {
        super(context, textViewResourceId, items);
        this.items = items;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Voicemail vm = items.get(position);
        View v = convertView;

        if (v == null) {
            LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.voicemails_pme_row, null);
        }
        if (vm != null) {
            TextView tt = (TextView) v.findViewById(R.id.toptext);
            TextView bt = (TextView) v.findViewById(R.id.bottomtext);
            TextView nm = (TextView) v.findViewById(R.id.length);

            if (tt != null) 
            {
                tt.setText(vm.getPhoneNumber());
                if(vm.getNewStatus())
                    tt.setTypeface(null, Typeface.BOLD);
            }

            if(bt != null)
            {
                bt.setText(vm.getDate());
            }

            if(nm != null)
            {
                nm.setText(vm.getLength());
            }
        }
        return v;
    }
}

class CheckConnectionTask extends AsyncTask<String, Void, String> {
    private VoicemailsPME activity;
    private ProgressDialog dialog;
    private Context context;

    public CheckConnectionTask(VoicemailsPME activity)
    {
        this.activity = activity;
        context = activity;
        dialog = new ProgressDialog(context);
    }

    String username, password, str;
    @Override
    protected void onPreExecute() {
        if(firstTime)
        {
            this.dialog.setMessage("Loading...");
            this.dialog.show();
        }
    }


    @Override
    protected String doInBackground(String...arg0)
    {
        username = arg0[0];
        password = arg0[1];

        DefaultHttpClient httpclient = new DefaultHttpClient();
        Credentials creds = new UsernamePasswordCredentials(username, password);
        httpclient.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), creds);

        try{
            HttpPost post = new HttpPost("https://www.my.patlive.com/api/v1.0/Mailbox/" + mailboxId + "/messages?format=json");

            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);

            nameValuePairs.add(new BasicNameValuePair("username", username));
            nameValuePairs.add(new BasicNameValuePair("password", password));

            post.setEntity(new UrlEncodedFormEntity(nameValuePairs));

            HttpResponse response = httpclient.execute(post);
            str = inputStreamToString(response.getEntity().getContent()).toString();    

            if(str.contains("\"ErrorCode\":0"))
            {
                //data = str;
                return str;
            }

        } catch (IllegalStateException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();}
        return str;
    }

    @Override
    protected void onPostExecute(String newData)
    {
        if(dialog.isShowing())
        {
            dialog.dismiss();
        }
        data = newData;
        getVoicemails();

        m_adapter.notifyDataSetChanged();

        listView.onRefreshComplete();
    }
}

}

  • 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-17T11:23:42+00:00Added an answer on June 17, 2026 at 11:23 am

    I think that your getVoicemail() method is the culprit.

    Because of the way that the adapter works, it’s using the backing array you provided originally (m_voicemails), and when you refresh it you create a new list but the original one is not cleared and then you just add on top of that.

    public void run() {
        //Try adding m_adapter.clear() here
        if(m_voicemails != null && m_voicemails.size() > 0){
            for(int i=0;i<m_voicemails.size();i++)
                m_adapter.add(m_voicemails.get(i)); 
        }
    }
    

    I’ve found that it’s clearer to keep a list of the data separate from your adapter and then just feed that data into the adapter (using a set instead of an add).

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

Sidebar

Related Questions

Every time i make a new JFrame object, the frame appears in the 0,0
Every time vim starts it shows 'No mapping found' warnings. I'm using the tutorial
For some reason lately, every time I pull and get a merge conflict, running
I am trying to pull data from a Database using C#.net and use a
I want to pull an RSS feed via jQuery AJAX, but every time I
I'm using django staticfiles + django-storages and Amazon S3 to host my data. All
Every time I pull code into my repository after making changes to JS or
I am using multiple queries to pull data from the same server in my
Every time i reset & seed my database it wipes out the standard admin@example.com
Every time when I'm trying to load the .dll in my application, I'm getting

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.