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

  • SEARCH
  • Home
  • 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 8899879
In Process

The Archive Base Latest Questions

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

The AsynctaskLoader is called multiple times and I get 3 items (2 duplicates) on

  • 0

The AsynctaskLoader is called multiple times and I get 3 items (2 duplicates) on the listfragment. (I do not want to clear, since I want to implement an endless scroller). If I remove items (adapter.remove) when onLoadFinished is called I still get two items (one duplicate). If i call adapter.clear onLoadFinished I get 1 item, but can’t implement an endless scroller then. The endless scroller is implemented by calling a loader with a new idea and a new bundle.

        public class ArticlePreviewAdapter extends ArrayAdapter<ArticlePreview>  {

        private final LayoutInflater inflater;
        private final ImageUpdater imageUpdater;



        public ArticlePreviewAdapter(Context context, ImageUpdater imageUpdater) {
            super(context, android.R.layout.simple_list_item_1);
            android.util.Log.d("SCROLL", "ArticlePreviewAdapter.ArticlePreviewAdapter" );

            this.inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);     
            this.imageUpdater = imageUpdater;
        }


        public void setData(ArticlePreview data) {
            //clear();      
            if (data != null) {         
                add(data);
                //this.add(data);           
            }
        }   

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {

            View view;

            if (convertView == null) {
                view = inflater.inflate(R.layout.article_preview, parent, false);
            } 
            else {
                view = convertView;
            }

            ArticlePreview articlePreview = getItem(position);      

            android.util.Log.d("SCROLL", "ArticlePreviewAdapter.getView pos: " + position);

            ((TextView) view.findViewById(R.id.article_preview_title)).setText(articlePreview.getTitle());
            ((TextView) view.findViewById(R.id.article_preview_info)).setText(articlePreview.getInfo());

            ImageView imageView = ((ImageView) view.findViewById(R.id.article_preview_image));
            Bitmap bitmap = this.imageUpdater.accessDirectly(articlePreview.getImageLink());

            if (bitmap != null) {
                imageView.setImageBitmap(bitmap);
            }
            else {
                this.imageUpdater.add(new ImageViewWebUpdate(view.hashCode(),
                        imageView, 100, 75, articlePreview.getImageLink()));
            }       

            return view;
        }
        }

The Loader class

public class ArticlePreviewLoader extends AsyncTaskLoader<List<ArticlePreview>>
{

    private String type;
    private String nid;
    private String start;
    private String end;

    private List<ArticlePreview> data;

    public ArticlePreviewLoader(Context context, Bundle args)
    {
        super(context);

        this.type = (String) args.get("type");
        this.nid = (String) args.get("nid");
        this.start = (String) args.get("start");
        this.end = (String) args.get("end");
    }

    /**
     * load JSON data, parse it and return.
     */
    @Override
    public List<ArticlePreview> loadInBackground()
    {

        android.util.Log.d("LOAD", "ArticlePreviewLoader.loadInBackground");

        // even if fail return empty list and print exception stack trace
        LinkedList<ArticlePreview> list = new LinkedList<ArticlePreview>();
        URL url;
        HttpURLConnection httpURLConnection = null;

        --

        android.util.Log.d("LOAD", "ArticlePreviewLoader.loadInBackground return");

        return Collections.unmodifiableList(list);
        //return list;
    }

    @Override
    protected void onStartLoading()
    {

        if (data != null)
            deliverResult(data);

        if (takeContentChanged() || data == null)
            forceLoad();
    }

    @Override
    protected void onStopLoading()
    {

        //super.onStopLoading();
        cancelLoad();
    }

    @Override
    protected void onReset()
    {
        super.onReset();

        onStopLoading();
        data = null;
    }
}

Help would be appreciated.. I’m stuck on this for a day now.

EDIT

Manifest code:

    <uses-sdk
        android:minSdkVersion="13"
        android:targetSdkVersion="16" />

    <uses-permission android:name="android.permission.INTERNET" />

     <!-- Permission to write to external storage -->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".SplashActivity"
            android:label="@string/title_activity_splash" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".LoginActivity"
            android:label="@string/title_activity_login" >
        </activity>
        <activity
            android:name=".ArticleForumActivity"
            android:label="@string/title_activity_article_forum" >
        </activity>
    </application>

</manifest>
  • 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:57:58+00:00Added an answer on June 15, 2026 at 12:57 am

    Use Set instead List<ArticlePreview> data

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

Sidebar

Related Questions

I want to implement an AsyncTaskLoader in my project using the Compatibility Package, so
I am trying to implement a ListFragment with AsynchTaskLoader that contains datasource but I
I am trying to implement a loader example on Android but can't get it
I want to fill a ListFragment with certain objects loaded from my MySql database.
I have ListFragment and AsyncTaskLoader which fetches data from internet. ListFragment is filled by
I've used AsyncTaskLoader to load a cursor from a database query. I followed Android
I have a ListFragment, currently populated with static data, fixed at compile time. I
I wondering where and when I should open/close my SQLiteDatabase connection in my AsyncTaskLoader.
I'm wondering if an Android Loader (more specifically AsyncTaskLoader ) is the correct job
I have a ViewPager with 3 Fragments in there. Each Fragment uses a AsyncTaskLoader

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.