开发者

Save Selections DialogInterface.OnMultiChoiceClickListener

开发者 https://www.devze.com 2023-04-09 04:22 出处:网络
I\'m trying to 开发者_开发技巧make an Android app, and I want to let users select Weekdays. now I\'ve got the AlertDialog setup and users can select several options.

I'm trying to 开发者_开发技巧make an Android app, and I want to let users select Weekdays. now I've got the AlertDialog setup and users can select several options. But I can't figure out how to save the selections when the user clicks the "OK" button.

Code:

new AlertDialog.Builder(this)
        .setTitle("Weekdays")
        .setMultiChoiceItems(weekdayOptions, selections, new DialogInterface.OnMultiChoiceClickListener()
        {
            public void onClick(DialogInterface dialog, int whichButton, boolean isChecked) 
                {

                    if( selections[whichButton] == true)
                        {
                            //Only need the selected(True) values
                            Log.d(TAG, "Choice: " + whichButton);   
                        }

                    Log.d(TAG, "Weekdays Selected: " + whichButton + selections[whichButton]);
                    selections[whichButton] = isChecked;    
                }
        })
        .setPositiveButton("OK", new DialogButtonClickHandler())
        .create()
        .show();
    }


    public class DialogButtonClickHandler implements DialogInterface.OnClickListener
    {
        public void onClick( DialogInterface dialog, int clicked ) 
        {
            switch(clicked) 
            {
                case DialogInterface.BUTTON_POSITIVE:
                    //I want to check here what the user selected
                    break;
            }
        }
    }

So when the user hits the BUTTON_POSITIVE I want to save the whichButton and the selections[whichButton] in I think a two-dimension array.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号