如何在AlertDialog中保存状态?

时间:2014-10-22 11:51:05

标签: android alertdialog

如何在AlertDialog中保存状态,以便在关闭并再次运行后可以保存应用程序状态?

private void CreateView(final Context context) {
        // TODO Auto-generated method stub
        AlertDialog.Builder builder = new AlertDialog.Builder(AndjeloOne.this);
        LayoutInflater inflater = AndjeloOne.this.getLayoutInflater();
        View v = inflater.inflate(R.layout.dialog_add, null);
        builder.setView(v)
                .setPositiveButton("Save", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                    }
                })
                .setTitle("Text Size");
        final SeekBar sbBetVal = (SeekBar) v.findViewById(R.id.seekBar1);
        final TextView tvBetVal = (TextView) v.findViewById(R.id.tvBetVal);
        final TextView t1 = (TextView) findViewById(R.id.textViewNulin);
        sbBetVal.setMax(24);
        sbBetVal.setProgress(0);
        sbBetVal.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub
            }

            @Override
            public void onProgressChanged(SeekBar seekBar, int progress,
                                          boolean fromUser) {
                // TODO Auto-generated method stub
                int size = 12;
                t1.setTextSize(size + progress);
                tvBetVal.setText(String.valueOf(progress));
            }
        });

        builder.create();
        builder.show();
    }

1 个答案:

答案 0 :(得分:0)

您可以使用Shared Preferances并存储标记。每次应用程序启动时,您都可以阅读标记并显示或显示警报。