To change the check box in a dialog box with multiple choices, you need a custom adapter for your dialog to have access to the list views. Then you call the setCheckMarkDrawable method of the setCheckMarkDrawable class.
Here is an example:

res/drawable file inside res/drawable
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="true" android:drawable="@drawable/checkbox_checked" /> <item android:state_pressed="true" android:drawable="@drawable/checkbox_checked" /> <item android:drawable="@drawable/checkbox_default" /> </selector>
DialogUtil.java File
package example.dialog; import android.app.AlertDialog; import android.content.Context; import android.util.Log; import android.view.*; import android.widget.*; import android.widget.AdapterView.OnItemClickListener; public class DialogUtil { private DialogUtil() { } public static AlertDialog show(Context context) { String[] items = {"text 1", "text 2", "text 3"}; AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle("Test") .setPositiveButton("OK", null) .setAdapter(new CustomAdapter(context, items), null); AlertDialog dialog = builder.show(); ListView list = dialog.getListView(); list.setItemsCanFocus(false); list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); list.setOnItemClickListener(listener); return dialog; } private static OnItemClickListener listener = new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Log.i("DialogUtil", "Clicked on " + view); } }; private static class CustomAdapter extends ArrayAdapter<String> { public CustomAdapter(Context context, String[] array) { super(context, android.R.layout.simple_list_item_multiple_choice, array); } @Override public View getView(int position, View convertView, ViewGroup parent) { View view = super.getView(position, convertView, parent); if (view instanceof CheckedTextView) { CheckedTextView checkedView = (CheckedTextView) view; checkedView.setCheckMarkDrawable(R.drawable.default_checkbox); } return view; } } }
NOTE. If you just use AlertDialog , then before you get the ListView , you call show , firstly, as described above.
However, if you use DialogFragment and onCreateDialog , you will get a ListView , inside onStart .
KitKat Oct 25 '13 at 19:36 on 2013-10-25 19:36
source share