Harry .Naeem
Harry .Naeem

Reputation: 1331

Selected Radio button in Alert Dialog doesn't show up

I have created an Alert Dialog with Radio buttons using single choice items and have passed an array of options to it. When i select the value it it working good but when i open the dialog again, the selected radio button does not show.

Here is my code for it:

private void openBufferSizePopup() {
    AlertDialog.Builder mBuilder = new AlertDialog.Builder(getContext());
    mBuilder.setTitle("Buffer Size");
    int checkedIndex = getArrayIndex(sizes, Constants.BUFFER_BEFORE);
    mBuilder.setSingleChoiceItems(buffer_sizes, checkedIndex, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            Constants.BUFFER_SIZE = sizes[i];
            SharedPreferences.Editor editor = getContext().getSharedPreferences(TUNEIN2, MODE_PRIVATE).edit();
            editor.putInt(Constants.BUFFER_SIZE_STR, Constants.BUFFER_SIZE);
            editor.apply();
            bufferSizeText.setText("Keep a buffer of " + Constants.BUFFER_SIZE + " minutes while playing");
            dialogInterface.dismiss();
        }
    });
    mBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.dismiss();
        }
    });

    AlertDialog mDialog = mBuilder.create();
    mDialog.show();
}

Following is the screenshot of the Alert dialog when opened again:Image

The first value is the one i have selected and its radio button is not appearing. Can someone tell me why is that? Thanks

Upvotes: 0

Views: 483

Answers (1)

Joey Dalu
Joey Dalu

Reputation: 1113

Your theme is probably using a white color (or something similar to the dialog's background) as it's colorAccent which is used to theme such buttons. Check your colors.xml file and make sure your colorAccent isn't white.

<color name="colorAccent">#000000</color>

Also make sure your app style (in styles.xml) references that color, or that it uses a different color than white as well.

<item name="colorAccent">@color/colorAccent</item>

Upvotes: 1

Related Questions