Creating Email-style RecyclerView with selectable items and contextual ActionBar

I want to build a list similar to what you see in email apps like Gmail. Each row should have a checkbox and some text fields stacked vertically. I need to handle two different click events - one when someone taps the checkbox and another when they tap anywhere else on the row.

I also want the ActionBar to change when items are selected, showing options like “Select All” or “Delete Selected” just like in modern email apps.

Here’s my current layout attempt:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="8dp">

    <CheckBox android:id="@+id/itemCheckbox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_alignParentStart="true" />

    <LinearLayout android:id="@+id/contentContainer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_toEndOf="@id/itemCheckbox"
        android:orientation="vertical"
        android:layout_marginStart="12dp"
        android:clickable="true"
        android:focusable="true">

        <TextView android:id="@+id/subjectText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="18sp"
            android:textStyle="bold" />

        <TextView android:id="@+id/timestampText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="14sp"
            android:textColor="#666666" />

    </LinearLayout>

</RelativeLayout>

The layout looks right but I’m stuck on the click handling part. I tried using CHOICE_MODE_MULTIPLE_MODAL with a custom MultiChoiceModeListener but can’t get the checkbox to sync properly with the selection state.

I’m using a custom CursorAdapter to populate data from SQLite. Should I be setting up the click listeners in the adapter’s getView method? Has anyone got this working properly before?

The checkbox sync issue happens because you’re fighting the framework - trying to use ListView’s built-in selection while managing your own checkbox states at the same time. I ditched ListView’s selection framework entirely and built my own. Here’s what worked: Create a boolean array that matches your cursor size. In getView, always set the checkbox state from this array - don’t let checkboxes maintain their own state. When someone clicks a checkbox, update your boolean array at that position and call notifyDataSetChanged. For ActionBar integration, implement ActionMode manually. Start it when the first item gets selected, finish it when nothing’s selected. The trick is treating checkboxes as purely visual - they just reflect your data state, they’re not interactive controls with their own logic. This killed all the weird sync bugs I was getting with built-in selection modes.

Everyone’s suggesting manual state management, but you’re just rebuilding what should be automated.

I hit this same problem building a code review tool. Don’t wrestle with CursorAdapter sync and boolean arrays - automate the selection workflow instead.

Here’s the deal: SQLite data changes, selections happen, ActionBar updates. Perfect automation chain. Set up a workflow that watches your database, handles selection events, and triggers UI updates automatically.

Someone clicks a checkbox? The workflow processes the state change and updates everything downstream. ActionBar shows when items are selected, batch deletes work seamlessly, zero manual sync code.

The workflow treats selection state as data, not UI logic. Way cleaner than tracking HashSets or SparseBooleanArrays in your adapter.

Your layout’s fine. Just hook it to an automated backend instead of fighting Android’s selection framework.

Your layout looks good, but you’re mixing framework selection modes with manual checkbox handling. I hit this same issue building a document management app. Skip the built-in selection stuff entirely and manage state yourself. Make a custom adapter with a SparseBooleanArray to track which positions are selected. In bindView, set checkbox state from your array instead of letting it handle its own state. For clicks, add listeners to both the checkbox and row that update your SparseBooleanArray and notify the adapter. When selections change, use an interface to tell your Activity to toggle ActionMode. You’ll have full control without fighting Android’s built-in behaviors that weren’t made for this.

you’re handling too much at once. drop CHOICE_MODE_MULTIPLE_MODAL - it’s more trouble than it’s worth. just manage your own selection state in the adapter using a HashSet or boolean array. set click listeners on both the checkbox and row in bindView/getView, then toggle the HashSet manually and update the action bar. you’ll have way more control and won’t deal with those annoying sync issues.

Been there, done that. Managing click states and syncing checkboxes with ActionBar turns into a nightmare when you handle everything in the adapter.

Skip the CursorAdapter and MultiChoiceModeListener mess - automate it instead. Set up a workflow that watches your SQLite database and updates the UI automatically. No more manual sync logic.

I built this for a client last year. User selects or deletes items, the workflow processes everything - database updates, UI changes, the works. Goodbye checkbox sync headaches and complex adapter code.

The workflow handles selection state, triggers ActionBar changes, and manages batch operations like “Select All” or “Delete Selected.” Way less boilerplate.

Prototype this approach - you’ll see how much cleaner it gets when you automate state management instead of tracking everything manually.