No Name
No Name

Reputation: 783

How to remove a first check Mark in AlertDialog.Multiple Choice

In the AlertDialog from somewhere appeared there is another checkMark Lollypop! And I need to remove it and leave your own. Prompt, who can faced with?

enter image description here

AlertDialog:

mSurchargeBtn.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {

        boolean[] checkedItems = new boolean[surchargeListNames.length];
        int count = surchargeListNames.length;

        for (int i = 0; i < count; i++)
            checkedItems[i] = selectedSurchargeItems.contains(surchargeListNames[i]);

        AlertDialog.Builder builder = new AlertDialog.Builder(DetailsActivity.this, R.style.AlertDialogCustom);
        builder.setMultiChoiceItems(surchargeListNames, checkedItems, new DialogInterface.OnMultiChoiceClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                if (isChecked)
                    selectedSurchargeItems.add(surchargeListNames[which]);
                else
                    selectedSurchargeItems.remove(surchargeListNames[which]);
            }
        });
        builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

            }
        });

        AlertDialog dialog = builder.create();
        dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);

        dialog.show();
}

Style:

<style name="AlertDialogCustom" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="android:checkMark">?android:attr/textCheckMark</item>
</style>

Upvotes: 0

Views: 131

Answers (1)

Udayaditya Barua
Udayaditya Barua

Reputation: 1162

You can maybe define a style extending Widget.AppCompat.CompoundButton.CheckBox

For example

<style name="mycheckbox" parent="Widget.AppCompat.CompoundButton.CheckBox">
    <item name="android:button">@null</item>
</style>

and in your main style

<style name="AlertDialogCustom" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="android:checkMark">?android:attr/textCheckMark</item>
    <item name="android:checkboxStyle">@style/mycheckbox</item>
</style>

I haven't tested this though. Good luck!

Upvotes: 1

Related Questions