Where to call restartLoader in ListView Fragment using ActionBarSherlock and SQLiteCursorLoader

I'm doing a ListView in a fragment using loaders, ActionBarSherlock and SqliteCursorLoader. The ListView basically shows a list of dates and GPS coordinates. I can load the inital ListView just fine. I want to be able to reload the ListView upon clicking of a button to go forward and back in time and show the relevant data.

My problem is that I must not be calling restartLoader() in the right place, Eclipse is giving me a compile error when I try and call it using "this" as the third parameter. It is saying that "this" is of type View, and it needs to be of type LoaderCallbacks. How do I get the third parameter? I tried to use all variations of getSherlockActivity().getSupportLoaderManager().getLoader(LOADER_ID) and tried to cast to LoaderCallbacks and no luck.

This is my first attempt using a Loader.

Here is my onActivityCreated:

public void onActivityCreated(Bundle savedInstanceState) {

    gps = new GPSTracker(getActivity());
    mGPSDC = new GPSDateCoordinates();
    Log.d(TAG, "onActivityCreated");
    //enables buttons for next and previous months
    adapter= new SimpleCursorAdapter(getActivity(), R.layout.row, null, new String[] {
            myDbHelper.COLUMN_DISTANCE, myDbHelper.COLUMN_FORMATTEDSTART }, 
            new int[] { R.id.title, R.id.value },0);

    btnDate.setText(getMonth(BaseMonth) + " " + String.valueOf(BaseYear));
    getSherlockActivity().getSupportLoaderManager().initLoader(LOADER_ID, null, this);

    // show next month's data
    btnNext.setOnClickListener(new View.OnClickListener() {
        public void onClick(View arg0) {
                getSherlockActivity().getSupportLoaderManager().restartLoader(LOADER_ID, null, this);



and here is the Loader code:

public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {

    loader = new SQLiteCursorLoader(getActivity().getApplicationContext(), myDbHelper,
    return loader;


public void onLoadFinished(Loader<Cursor> arg0, Cursor cursor) {


public void onLoaderReset(Loader<Cursor> arg0) {



You'll want to use YourActivityClassName.this rather than this (which is the View.OnClickListener class instance) in order to refer to the Activity's instance.

Need Your Help

Layout of Google calendar populated from ical feed

google-calendar icalendar

I'm populating a number of calendars in Google Calendar via dynamically generated iCalendar feeds. These calendars are being correctly imported into Google Calendar, but their events appear intermi...

How to Register a Type in ServiceStack without using Generics

c# asp.net servicestack

It is possible to register a type in ServiceStack Container using a object instance and its Type?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.