Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I had the same issue myself: how to toggle multiple select CheckedTextView in a custom layout (i.e not using <strong>android.R.layout.simple_list_item_multiple_choice</strong>)</p> <p>The following worked for me. The example I have is a custom view that is provided an adaptor extended from <strong>SimpleCursorAdapter.</strong></p> <p>My custom view (row_contact.xml):</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:layout_width="fill_parent"&gt; &lt;CheckedTextView android:id="@android:id/text1" android:layout_width="fill_parent" android:layout_height="?android:attr/listPreferredItemHeight" android:textAppearance="?android:attr/textAppearanceLarge" android:gravity="center_vertical" android:paddingLeft="6dip" android:paddingRight="6dip" android:checkMark="?android:attr/listChoiceIndicatorMultiple" /&gt; &lt;TextView android:text="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/tvNumber" android:layout_gravity="bottom" android:paddingLeft="6dip" android:paddingRight="6dip" /&gt; &lt;/FrameLayout&gt; </code></pre> <p>The adaptor is created in ListActivity.OnCreate, which calls setupViews():</p> <pre><code> private void setupViews() { bOk = (Button) findViewById(R.id.ButtonOK); bCancel = (Button) findViewById(R.id.ButtonCancel); FListView = getListView(); // bOk.setText("Select"); // FListView.setItemsCanFocus(false); FListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); // bOk.setOnClickListener(this); bCancel.setOnClickListener(this); // ContentResolver content = getContentResolver(); Cursor cursor = ApplicationHelper.MobilePhoneContacts(content); startManagingCursor(cursor); ListAdapter adapter = new CheckedCursorAdapter( SelectContacts.this, R.layout.row_contact, cursor, new String[] {People.NAME, People.NUMBER}, new int[] {android.R.id.text1, R.id.tvNumber}); setListAdapter(adapter); } </code></pre> <p>The Custom adaptor:</p> <pre><code> public class CheckedCursorAdapter extends SimpleCursorAdapter { Activity context; Cursor c; public CheckedCursorAdapter(Activity context, int rowContact, Cursor cursor, String[] strings, int[] is) { super(context, rowContact, cursor, strings, is); this.context = context; this.c = cursor; } public View getView(int position, View convertView, ViewGroup parent) { View row = convertView; ContactRowWrapper wrapper; if (row == null) { LayoutInflater inflater=context.getLayoutInflater(); row = inflater.inflate(R.layout.row_contact, null); // wrapper = new ContactRowWrapper(row); row.setTag(wrapper); } else { wrapper = (ContactRowWrapper)row.getTag(); } c.moveToPosition(position); wrapper.getTextView().setText( c.getString(c.getColumnIndex(Contacts.People.NUMBER)) ); wrapper.getcheckBox().setText( c.getString(c.getColumnIndex(Contacts.People.NAME)) ); wrapper.getcheckBox().setChecked(getListView().isItemChecked(position)); // return row; } } </code></pre> <p>The crucial bit of code for for me was to get check boxes working was:</p> <pre><code>wrapper.getcheckBox().setChecked(getListView().isItemChecked(position)); </code></pre> <p>Hope this helps you or anyone else who stumbles onto this question.</p> <p>Also, pardon my Java noobness... I've only started Java a few weeks ago.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload