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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:52:16+00:00 2026-06-13T09:52:16+00:00

I have subclassed SimpleCursorAdapter in order to create a custom list entry layout containing

  • 0

I have subclassed SimpleCursorAdapter in order to create a custom list entry layout containing a Button. I can get as far as making the button write to the log. My intent is to launch an AlertDialog, but I have yet to find a way to get a FragmentManager to launch the DialogFragment. I’m using the fragment compatibility components.

For this case I realize there may be simpler solutions which avoid the use of a SimpleCursorAdapter, but I am trying to learn this case before I work on more complicated components.

Here is the adapter:

public class ActiveProfileAdapter extends SimpleCursorAdapter {
    private static final String DEBUG_TAG = "ActiveProfileAdapter";
    private final Cursor dataCursor;
    private final LayoutInflater mInflater;

    public ActiveProfileAdapter(final Context context, final int layout, final Cursor dataCursor, final String[] from,
            final int[] to, final int flags) {
        super(context, layout, dataCursor, from, to, flags);
        this.dataCursor = dataCursor;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public View getView(final int position, View convertView, final ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.profilebar_list_item, null);

            holder = new ViewHolder();
            holder.button1 = (Button) convertView.findViewById(R.id.currentprofile);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        dataCursor.moveToPosition(position);
        final int label_index = dataCursor.getColumnIndex(ProfilesColumns.USERNAME);
        if (label_index == -1) {
            Log.d(DEBUG_TAG, "Bad column name");
        }

        final String label = dataCursor.getString(label_index);
        holder.button1.setText(label);
        holder.button1.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(final View v) {
                Log.d(DEBUG_TAG, "Launch AlertDialog Fragment when this button is pressed");
            }
        });

        return convertView;
    }

    static class ViewHolder {
        Button button1;
    }
}

Here is the fragment which calls the adapter:

public class ActiveProfileFragment extends ListFragment implements LoaderManager.LoaderCallbacks<Cursor> {
    private static final int LIST_LOADER = R.loader.browsefragloader;
    protected int layout = R.layout.profilebar_fragment;
    protected SimpleCursorAdapter listAdapter;

    protected final Uri table = ProfileProvider.URI_ACTIVEPROFILEVIEW;
    protected String[] uiBindFrom = { ProfilesColumns.USERNAME };
    protected String[] createProjection = { CommonDatabaseHelper._ID, ProfilesColumns.USERNAME };
    protected int[] uiBindTo = { R.id.currentprofile };

    // layout for list item
    protected int entryLayout = R.layout.profilebar_list_item;

    Button openProfile;

    public ActiveProfileFragment() {
        super();
    }

    @Override
    public void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Cursor c = getActivity().getContentResolver().query(table, createProjection, null, null, null);
        listAdapter = new ActiveProfileAdapter(getActivity().getApplicationContext(), entryLayout, c, uiBindFrom,
                uiBindTo, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
        getLoaderManager().initLoader(LIST_LOADER, null, this);
        setListAdapter(listAdapter);
    }

    @Override
    public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
        final View view = inflater.inflate(layout, container, false);
        return view;
    }

    @Override
    public Loader<Cursor> onCreateLoader(final int id, final Bundle args) {
        final String[] projection = createProjection;
        final CursorLoader cursorLoader = new CursorLoader(getActivity(), table, projection, null, null, null);
        return cursorLoader;
    }

    @Override
    public void onLoadFinished(final Loader<Cursor> loader, final Cursor cursor) {
        listAdapter.swapCursor(cursor);
    }

    @Override
    public void onLoaderReset(final Loader<Cursor> loader) {
        listAdapter.swapCursor(null);
    }
}

And here is the activity which contains the fragment:

public class BrowseActivity extends FragmentActivity {
    protected int layout = R.layout.browse_viewer;

    final Fragment profileBarFragment = new ActiveProfileFragment();
    final Fragment fragment0 = new BrowseFragment();

    @Override
    public void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(layout);
        final android.support.v4.app.FragmentManager fm = getSupportFragmentManager();
        final android.support.v4.app.FragmentTransaction transaction = fm.beginTransaction();
        transaction.replace(R.id.profilebarfragment, profileBarFragment);
        transaction.replace(R.id.fragment, fragment0);
        transaction.commit();
    }
}

Thank you.

Resolved
I hit upon a very simple solution. I moved the adapter into the fragment activity so that I could reference the fragment’s components locally.

  • 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-13T09:52:18+00:00Added an answer on June 13, 2026 at 9:52 am

    Define the adapter inside the fragment so that it has access to the activity’s resources.

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

Sidebar

Related Questions

I have subclassed the RadioButtonList control in order to create a Control Adapter that
I have subclassed a text-field form field in Django to create my own custom
I have subclassed a control in C# WinForms, and am custom drawing text in
I have subclassed a UITableViewCell and within this class I want to get it's
In our iOS app, we have subclassed a UISlider in order to use a
I have subclassed UITableViewCell to make a custom cell for a tableView. I add
I have subclassed the UICollectionViewLayoutAttributes class and added a few custom properties. In my
I have subclassed Dialog in order to display a popup. This dialog contains a
I have subclassed UITableViewCell for a custom cell view along the lines as follows:
so I have subclassed a UIViewController that I create. The question is, is there

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.