1

I have an activity for user with a button called choose days when user clicks the button it show a alert dialog for selecting the day of week

now i want when user select multiple days

then previously selected check box will show in check position and remains with uncheck position

MMG
  • 3,226
  • 5
  • 16
  • 43
Sinku Paliwal
  • 213
  • 1
  • 3
  • 8

2 Answers2

2

Here is a nice library for that, I use it for my project. enter image description here

Step 1:

Add these lines to your build.gradle file

  dependencies {
compile 'com.afollestad:material-dialogs:0.7.7.0'
}

repositories 
maven { url 'https://dl.bintray.com/drummer-aidan/maven' }
}

Step 2: In code where you want to show dialog add this:

new MaterialDialog.Builder(this)
    .title(R.string.title)
    .items(R.array.items)
    .itemsCallbackMultiChoice(null, new MaterialDialog.ListCallbackMultiChoice() {
        @Override
        public boolean onSelection(MaterialDialog dialog, Integer[] which, CharSequence[] text) {
            /**
             * If you use alwaysCallMultiChoiceCallback(), which is discussed below,
             * returning false here won't allow the newly selected check box to actually be selected.
             * See the limited multi choice dialog example in the sample project for details.
             **/
             return true;
        }
    })
    .positiveText(R.string.choose)
    .show();

items(R.array.items) - that should be an array of string values in your resources.

P.S. Please read the documentation of this library, it very clear and simply)

enter image description here

Dennis Zinkovski
  • 1,821
  • 3
  • 25
  • 42
0

Maybe you can take a look at the Android standard. Dialogs

It also shows you how to create a custom dialog. They have an example of a list with checkboxes

R. Adang
  • 593
  • 3
  • 13
  • Go to the link and then scroll down. there is a example of a custom dialog. you can change te login dialog view to your own layout. I'm not going to post code here, that is not good for the readability. – R. Adang Jul 23 '15 at 10:09
  • Take a look at this code in the example: `LayoutInflater inflater = getActivity().getLayoutInflater(); // Inflate and set the layout for the dialog // Pass null as the parent view because its going in the dialog layout builder.setView(inflater.inflate(R.layout.dialog_signin, null))` – R. Adang Jul 23 '15 at 10:10
  • 1
    @R. Adang: Your link to Dialogs shows Page Not Found error. Please update. – Madhan Mar 22 '17 at 09:23