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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:20:28+00:00 2026-06-14T07:20:28+00:00

I have a ListView with android:choiceMode=multipleChoice. I fill this ListView from a Cursor through

  • 0

I have a ListView with android:choiceMode=”multipleChoice”. I fill this ListView from a Cursor through a SimpleCursorAdapter. Is there really no way to directly bind the “CheckBox” of the ListView’s CheckedTextView layout to a boolean value from the cursor?

Currently I loop through the cursor calling ListView.setItemChecked() if the value is true:

private void showMyData(long myId) {
    // fill the list
    String[] fromColumns = { "myTextColumn" };
    int[] toViews = { android.R.id.text1 };
    Cursor myCursor = _myData.readData(myId);
    CursorAdapter myAdapter = new SimpleCursorAdapter(this,
        android.R.layout.simple_list_item_multiple_choice,
        myCursor, fromColumns, toViews);
    ListView myListView = (ListView) findViewById(R.id.myListView);
    myListView.setAdapter(myAdapter);
    // mark items that include the object specified by myId
    int myBooleanColumnPosition = myCursor
        .getColumnIndex("myBooleanColumn");
    for (int i = 0; i < myCursor.getCount(); i++) {
        myCursor.moveToPosition(i);
        if (myCursor.getInt(myBooleanColumnPosition ) == 1) {
            myListView.setItemChecked(i, true);
        }
    }
}

That does the job. But I would like to have code like this:

String[] fromColumns = { "myTextColumn", "myBooleanColumn" };
int[] toViews = { android.R.id.text1, android.R.id.Xyz };

and have no loop. Am I missing something here or is it Android?

EDIT:
I tried this as suggested by Luksprog:

public boolean setViewValue(View view, Cursor cursor,
        int columnIndex) {
    CheckedTextView ctv = (CheckedTextView) view;
    ctv.setText(cursor.getString(cursor
            .getColumnIndex("myTextColumn")));
    if (cursor.getInt(cursor.getColumnIndex("myBooleanColumn")) == 1) {
        ctv.setChecked(true);
        Log.d("MY_TAG", "CheckBox checked");
    }
    return true;
}

That logged checking the CheckBox but didn’t actually do it. Maybe that’s a bug on my side. And while it’s even more complicated than the initial loop at least it feels like one is using the framework, not working against it. So thank you Luksprog for the answer.

But to sum it up: Android is actually missing the straight forward approach.

  • 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-14T07:20:30+00:00Added an answer on June 14, 2026 at 7:20 am

    Use a SimpleCursorAdapter.ViewBinder on your adapter. Make sure your Cursor has the boolean values column in it and then:

    String[] fromColumns = { "myTextColumn" };
    int[] toViews = { android.R.id.text1 };
    Cursor myCursor = _myData.readData(myId);
    CursorAdapter myAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_multiple_choice, myCursor, fromColumns, toViews);
    myAdapter.setViewBinder(new ViewBinder() {
           public boolean setViewValue (View view, Cursor cursor, int columnIndex) {
              // set the text of the list row, the view parameter (simple use cursor.getString(columnIndex))
              // set the CheckBox status(the layout used in the adapter is a CheckedTextView)
              return true;
           }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListView ( my_list.xml ): <ListView android:id=@+id/my_list android:layout_width=wrap_content android:layout_height=wrap_content android:choiceMode=singleChoice /> The
I have an android listview filled with items. Every item has a button. This
I have dynamic listview on my android client app that receive data from remote
I have a doubt in listview android. I am getting 3 dynamic values from
Suppose we have this example: http://techdroid.kbeanie.com/2009/07/custom-listview-for-android.html with source code available here: http://code.google.com/p/myandroidwidgets/source/browse/trunk/Phonebook/src/com/abeanie/ How can
Is it possible to make a multiple choice list with android:choiceMode=multipleChoice or setChoiceMode(ListView.CHOICE_MODE_MULTIPLE) on
I have a ListView (set to CHOICE_MODE_SINGLE) I have a SimpleCursorAdapter who fill my
I have a listView which defined like this in xml: <ListView android:id=@android:id/list android:layout_width=match_parent android:layout_height=match_parent
I have this Listview element: <ListView android:id=@+id/category_list android:layout_width=fill_parent android:layout_height=fill_parent android:layout_weight=1 android:background=@drawable/list_background android:layout_marginTop=10sp android:layout_marginLeft=10sp android:layout_marginRight=10sp
I have a listview : <ListView android:clickable=true android:id=@android:id/list android:layout_width=match_parent android:layout_height=wrap_content > </ListView> the elements

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.