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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:10:22+00:00 2026-06-15T14:10:22+00:00

I have an AsyncTask which loads Tweets from Twitter. I also have a PullToRefresh

  • 0

I have an AsyncTask which loads Tweets from Twitter.
I also have a PullToRefresh ListView… Whenever i pull to refresh it, the listview immediately clears and as soon as the data has been loaded, it’s getting filled into the listview.

I have other ListViews in my App all with the same stuff (PullToRefresh and Async data loading…). On the other ListViews this does not happen. Only on the Twitter ListView. What am I doing wrong?

Here is my Code:

    public class TwitterDownloader extends AsyncTask<Void, Void, String> {

    final Handler mHandler = new Handler();

    public TwitterDownloader() {
    }

    @Override
    public void onPreExecute() {
        super.onPreExecute();
    }

    @Override
    protected String doInBackground(Void... params) {
        twitter4j.Twitter twitter = new TwitterFactory().getInstance();

        listTweets.clear();

            List<twitter4j.Status> statuses = null;

            try {
                statuses = twitter.getUserTimeline(
                        MainActivity.TWITTER_USERNAME, new Paging(1, 50));
            } catch (TwitterException e) {
                e.printStackTrace();
                Log.e(MainActivity.LOG_TAG, "TwitterException");
            }

            try {
                for (twitter4j.Status status : statuses) {
                    listTweets.add(status.getText());
                }
            } catch (NullPointerException npe) {
            }
        return null;
    }

    @Override
    public void onPostExecute(String unused) {
        MyCustomAdapter myAdapter = new MyCustomAdapter(myContext,
                R.layout.row_twitter, listTweets);
        setListAdapter(myAdapter);
        getListView().setTextFilterEnabled(true);

        String lastUpdate = (new SimpleDateFormat(
                "HH:mm")).format(new Date());

        pullToRefreshView.onRefreshComplete();
        pullToRefreshView.setLastUpdatedLabel(getString(R.string.last_updated) + ": "
                + lastUpdate);
    }
  • 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-15T14:10:23+00:00Added an answer on June 15, 2026 at 2:10 pm

    I finally fixed it by adding all my clear() statements right before I fill up my list again (which is inside a try catch).

    So the new code inside my doInBackground method is:

    try {
                listTweets.clear();
                listUsernames.clear();
                listDates.clear();
                listImageURLs.clear();
                listURLsOfTweets.clear();
                for (twitter4j.Status status : statuses) {
                    listTweets.add(status.getText());
                    listUsernames.add(status.getUser().getName());
                    listDates.add(android.text.format.DateFormat
                            .getDateFormat(getApplicationContext()).format(
                                    status.getCreatedAt())
                            + " "
                            + android.text.format.DateFormat.getTimeFormat(
                                    getApplicationContext()).format(
                                    status.getCreatedAt()));
                    listImageURLs.add(status.getUser().getProfileImageURL()
                            .toString());
    
                    StringBuffer address = new StringBuffer();
                    address.append("http://twitter.com/#!/");
                    address.append(status.getUser().getScreenName());
                    address.append("/status/");
                    address.append(status.getId());
    
                    listURLsOfTweets.add(address.toString());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a code which download the apk from server by using Asynctask, Currently
I have a class that extends AsyncTask , which fetches the gps cordinates from
I have a listview which is filled by AsyncTask and I am trying to
I have a ListView populated by a SimpleAdapter, which gets values from an ArrayList
In my application, I have a WebView which loads any URL from the internet.
I have created an AsyncTask that loads data from a website then when I
I have the following asynctask class which is not inside the activity. In the
I am trying to create downloading progress. I have my class which extends AsyncTask:
I have an Activity class which has an attribute that references an AsyncTask instance
I have some problem with Android AsyncTask. There is an Activity which contains some

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.