单选菜单

     * pop a single choice dialog
     * choice sub
     */
    private void singelDialog(final String fileName,final int permission){
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setIcon(R.drawable.ic_launcher);
        builder.setTitle("请选择主体");

        List list = operateData.read(OperateFile_Imp.SUBJECT_FILE_NAME);
        Subject sub = null;
        String[] strs =  new String[list.size()];
        int j = 0;
        for (int i=0;inew Subject(list.get(i));
            if(sub.getUsername().equals(MainActivity.userName))//把当然用户去掉
                   j=i;
            strs[i]=sub.getUsername();
        }
        for (int i = j; i < list.size()-1; i++)
            strs[i] =  strs[i+1];

        String[] strs_ =  new String[list.size()-1];
        for (int i = 0; i < strs_.length; i++)
            strs_[i] = strs[i];

        final String sbStr[] = strs_;
        final int[] choice= new int[2];
         //    设置一个单项选择下拉框
        /**
         * 第一个参数指定我们要显示的一组下拉单选框的数据集合
         * 第二个参数代表索引,指定默认哪一个单选框被勾选上,1表示默认'女' 会被勾选上
         * 第三个参数给每一个单选项绑定一个监听器
         */
        builder.setSingleChoiceItems(sbStr, 1, new DialogInterface.OnClickListener()
        {
            @Override
            public void onClick(DialogInterface dialog, int which)
            {
               choice[0]=which;
            }
        });
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener()
        {
            @Override
            public void onClick(DialogInterface dialog, int which)
            {
               showToast(sbStr[choice[0]]+" ");
               entity.Strategy strate = new Strategy(sbStr[choice[0]],fileName,permission);
               operateData.write(strate.toString(), OperateFile_Imp.STRARERY_FILE_NAME,true);

            }
        });
        builder.setNegativeButton("取消", null);//取消对话框
        builder.show();//显示对话框
    } 

你可能感兴趣的:(Android)