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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:58:41+00:00 2026-06-09T20:58:41+00:00

I have a ListFragment , where I add a CursorAdapter to my ListView ,

  • 0

I have a ListFragment, where I add a CursorAdapter to my ListView, and I want to be able to click several rows, to use contextual action bar. I use SherlockActionbar, and it works fine, when I use a simple ArrayAdapter. But when I switch to CursorAdapter, it breaks. I cannot select multiple rows, only one. Any idea why it might happen?

In onActivityCreated I set up the list:

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mActionMode = null;
    mListView = getListView();
    FinTracDatabase database = mDatabaseProvider.get();
    Cursor cursor = database.getTransactionCursor(false);
    mCursorAdapter = new TransactionListAdapter(getSherlockActivity(), cursor);
    mListView.setAdapter(mCursorAdapter);
    mListView.setItemsCanFocus(false);
    mListView.setOnItemClickListener(this);
    mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
}

This is my Adapter:

private class TransactionListAdapter extends CursorAdapter {

    public TransactionListAdapter(Context context, Cursor cursor) {
        super(context, cursor, 0);
    }

    @Override
    public void bindView(View view, Context context, Cursor cursor) {
        bindToExistingView(view, cursor);
    }

    private void bindToExistingView(View view, Cursor cursor) {
        CheckedTextView amountView = (CheckedTextView) view;
        amountView.setText(cursor.getString(cursor.getColumnIndex(Transactions.TITLE)));
    }

    @Override
    public View newView(Context arg0, Cursor arg1, ViewGroup arg2) {
        LayoutInflater layoutInflater = getSherlockActivity().getLayoutInflater();
        View view = layoutInflater.inflate(android.R.layout.simple_list_item_multiple_choice, arg2, false);
        bindToExistingView(view, arg1);
        return view;
    }

}

And finally the onClickListener:

@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
    SparseBooleanArray checked = mListView.getCheckedItemPositions();
    boolean hasCheckedElement = true;
    for (int i = 0; i < checked.size() && !hasCheckedElement; i++) {
        hasCheckedElement = checked.valueAt(i);
    }

    if (hasCheckedElement) {
        if (mActionMode == null) {
            mActionMode = getSherlockActivity().startActionMode(new SelectingActionMode());
        }
    } else {
        if (mActionMode != null) {
            mActionMode.finish();
        }
    }
}

If I switch my Adapter to a simple ArrayAdapter, it works fine.

new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_multiple_choice, new String[]{"A", "B", "C"})

I am hopeless, and I have no idea, why this is happening.

  • 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-09T20:58:43+00:00Added an answer on June 9, 2026 at 8:58 pm

    In order for the ListView.CHOICE_MODE_MULTIPLE mode to work properly, each of the item in the adapter must return a unique value from the getItemId() method.

    The cursor you are using for your adapter is produced on these lines:

      FinTracDatabase database = mDatabaseProvider.get();
      Cursor cursor = database.getTransactionCursor(false);
    

    Could you check whether it has unique values on its “_id” column for each row? I am suspecting that they all share the same values, resulting in the behavior that you see.

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

Sidebar

Related Questions

i have about 60 fragments ListFragment , now i use each Listfragment with another
I have a ListView in a ListFragment that is populated via a database query.
Actually I thought the ListView of a ListFragment would have been created in OnActivityCreated
So I have a ListView and I want to change the color of each
I have a ListView (technically its a ListFragment , but I dont think that
I have a ListFragment Activity. I want to create a method for onItemClickedLongPress, so
I have a ListView (part of a ListFragment ), and I noticed that when
I have a ListFragment whose list should diplay the Albums of the device and
I have create a listfragment and a button which looks like as follows (
I have crated a class which extends the ListFragment . I have one button

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.