开发者

Save Selections DialogInterface.OnMultiChoiceClickListener

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜