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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:41:39+00:00 2026-06-12T06:41:39+00:00

I am using ActionbarSherlock with a SherlockListFragment that implements LoaderManager.LoaderCallbacks . In my ApplicationActivity

  • 0

I am using ActionbarSherlock with a SherlockListFragment that implements LoaderManager.LoaderCallbacks.

In my ApplicationActivity onCreate method I am using

setContentView(R.layout.application);

to set the layout — works great.

I am initializing the actionbar like so

ActionBar bar = getSupportActionBar();
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
bar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
bar.setDisplayHomeAsUpEnabled(false);
bar.setDisplayShowTitleEnabled(true);

// users event list     
bar.addTab(bar.newTab()
    .setTag("event_list")
    .setText(getString(R.string.list_events_header))
    .setTabListener(new TabListener<EventListFragment>(
        this, getString(R.string.list_events_header), EventListFragment.class, null)));

Within the ApplicationActivity, I have an AsyncTask that takes a couple of seconds to load on initial open, and when manually refreshed against the API – which means that I need to make sure I update the ListView on the fragment instantiated above, which I do in the onPostExecute method, here is how I do that:

// update the events fragment
EventListFragment fragment = (EventListFragment) getSupportFragmentManager().findFragmentById(R.string.list_events_header);
if(fragment != null) {
    // restart the loader for this fragment, refreshing the listview
    getSupportLoaderManager().restartLoader(0, null, fragment);
}

THIS ALL WORKS

Now, I wanted to put in a TabsAdapter to get the fancy swiping tabs, which I’ve done, and it works, but the last part I mentioned about the onPostExecute, doesnt work 🙁

This is my TabsAdapter:

package com.lateral.app.ui;

import java.util.ArrayList;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.ActionBar.Tab;

public class APPTabsAdapter extends FragmentPagerAdapter implements
        ActionBar.TabListener, ViewPager.OnPageChangeListener {
    private final Context mContext;
    private final ActionBar mActionBar;
    private final ViewPager mViewPager;
    private final ArrayList<TabInfo> mTabs = new ArrayList<TabInfo>();

    static final class TabInfo {
        private final Class<?> clss;
        private final Bundle args;

        TabInfo(Class<?> _class, Bundle _args) {
            clss = _class;
            args = _args;
        }
    }

    public APPTabsAdapter(ApplicationActivity activity, ViewPager pager) {
        super(activity.getSupportFragmentManager());
        mContext = activity;
        mActionBar = activity.getSupportActionBar();
        mViewPager = pager;
        mViewPager.setAdapter(this);
        mViewPager.setOnPageChangeListener(this);
    }

    public APPTabsAdapter(EventActivity activity, ViewPager pager) {
        super(activity.getSupportFragmentManager());
        mContext = activity;
        mActionBar = activity.getSupportActionBar();
        mViewPager = pager;
        mViewPager.setAdapter(this);
        mViewPager.setOnPageChangeListener(this);
    }

    public void addTab(ActionBar.Tab tab, Class<?> clss, Bundle args) {
        TabInfo info = new TabInfo(clss, args);
        tab.setTag(info);
        tab.setTabListener(this);
        mTabs.add(info);
        mActionBar.addTab(tab);
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mTabs.size();
    }

    @Override
    public Fragment getItem(int position) {
        TabInfo info = mTabs.get(position);
        return Fragment.instantiate(mContext, info.clss.getName(), info.args);
    }

    public void onPageScrolled(int position, float positionOffset,
            int positionOffsetPixels) {
    }

    public void onPageSelected(int position) {
        mActionBar.setSelectedNavigationItem(position);
    }

    public void onPageScrollStateChanged(int state) {
    }

    public void onTabSelected(Tab tab, FragmentTransaction ft) {
        Object tag = tab.getTag();
        for (int i = 0; i < mTabs.size(); i++) {
            if (mTabs.get(i) == tag) {
                mViewPager.setCurrentItem(i);
            }
        }
    }

    public void onTabUnselected(Tab tab, FragmentTransaction ft) {
    }

    public void onTabReselected(Tab tab, FragmentTransaction ft) {
    }
}

This is my updated onCreate method from the ApplicationActivity

mViewPager = new ViewPager(this);
mViewPager.setId(R.id.pager);

setContentView(mViewPager);

ActionBar bar = getSupportActionBar();
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
bar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
bar.setDisplayHomeAsUpEnabled(false);
bar.setDisplayShowTitleEnabled(true);

mTabsAdapter = new APPTabsAdapter(this, mViewPager);

// users event list     
mTabsAdapter.addTab(bar.newTab()
    .setTag("event_list")
        .setText(getString(R.string.list_events_header))
        .setTabListener(new TabListener<EventListFragment>(
            this, getString(R.string.list_events_header), EventListFragment.class, null)), EventListFragment.class, null);

And this is the update I made to my onPostExecute method in the ApplicationActivity

// update the events fragment
EventListFragment fragment = (EventListFragment) mTabsAdapter.getItem(0);
if(fragment != null) {
    // restart the loader for this fragment, refreshing the listview
    getSupportLoaderManager().restartLoader(0, null, fragment);
}

Basically, when it attempts to run my onPostExecute code

I get a NullPointerException from my cursorAdapter within the fragment.. but it found the fragment..

enter image description here

EDIT — Requested Code

public Loader<Cursor> onCreateLoader(int loaderId, Bundle args) {
    Log.d(TAG, "onCreateLoader");

    return new EventCursorLoader(getActivity());
}

public static final class EventCursorLoader extends SimpleCursorLoader {

    Context mContext;

    public EventCursorLoader(Context context) {
        super(context);

        Log.d("EventCursorLoader", "Constructor");

        mContext = context;
    }

    @Override
    public Cursor loadInBackground() {
        Log.d("EventCursorLoader", "loadInBackground");

        EventsDataSource datasource = new EventsDataSource(mContext, ((ApplicationActivity)mContext).getDbHelper());

        SharedPreferences app_preferences = PreferenceManager.getDefaultSharedPreferences(mContext);
        long userId = app_preferences.getLong("authenticated_user_id", 0);

        return datasource.getAllEvents(userId);
    }
}
  • 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-12T06:41:41+00:00Added an answer on June 12, 2026 at 6:41 am

    Attempting to retrieve the loader here is simply the wrong idea, as the purpose is to refresh the data. After doing some digging I found that I can notify more than 1 set of content load in my provider using

    getContext().getContentResolver().notifyChange(uri, null);
    

    which notifies it of change and refreshes, all this code can be deleted and replaced with a single line.

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

Sidebar

Related Questions

I set up a test app using ActionbarSherlock 4.0, which works fine in the
I am using ActionbarSherlock 4.0 - the problem is that when I set targetSdkVersion
I'm developping an application using ActionBarSherlock component. My goal is to target all devices
I'm using ActionBarSherlock in an Android project that I developed using Eclipse. I'd like
I'm using Actionbarsherlock and want to use a custom actionbar layout, but still want
I'm using ActionBarSherlock to implement an ActionBar with tabs in my application. When I
I am using ActionBarSherlock, in the ActionBar i have this custom layout to appear
I am using ActionBarSherlock Library. In a simple layout i have this code: <?xml
I'm using ActionBarSherlock and have set an icon using android:logo in my theme. I'd
I am using actionbarsherlock library to have action-bar in my application, I am also

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.