简体   繁体   English

Android对话框及其在屏幕方向更改时的状态维护

[英]Android dialog and maintaining of its state on screen orientation change

I m having trouble with maintaining the dialog on orientation change. I m having trouble with maintaining the dialog on orientation change. I m having trouble with maintaining the dialog on orientation change. I m using onSaveInstanceState, onRestoreInstanceState. m having trouble with maintaining the dialog on orientation change. I使用onSaveInstanceState,onRestoreInstanceState。 But i have a null in onRestore. 但是我在onRestore中有一个null。 I want the dialog to show the same values when i change orientation of the screen. 当我更改屏幕方向时,我希望对话框显示相同的值。 Thanx! 谢谢! Here is the dialog: 这是对话框:

private void ratedialog() {

        dialog = new Dialog(this);
        dialog.setContentView(R.layout.dialog);
        dialog.setTitle("Rate it!");
        dialog.setCancelable(true);
        dialog.show();

        seekbar = (SeekBar) dialog.findViewById(R.id.rate_seekbar);
        button_done = (Button) dialog.findViewById(R.id.button_done);
        seekbar_result = (TextView) dialog.findViewById(R.id.seekbar_result);
        checkBox_seen = (CheckBox) dialog.findViewById(R.id.checkBox_seen);

        button_done.setOnClickListener(EditActivity.this);
        seekbar.setOnSeekBarChangeListener(EditActivity.this);
        checkBox_seen.setOnCheckedChangeListener(EditActivity.this);

        Intent callingIntent = getIntent();
        if (callingIntent.getAction().equals(Intent.ACTION_OPEN_DOCUMENT)) {

            Movie movie = dbHandler.query(id);
            rate = movie.getRate();
            seen = movie.isSeen();

            seekbar.setProgress(rate);
            image_seen.setImageResource(R.drawable.seen);
            image_seen.setVisibility(View.INVISIBLE);
            checkBox_seen.setChecked(seen);
        }else if (callingIntent.getAction().equals(Intent.ACTION_EDIT)){
            seekbar.setProgress(rate);
            image_seen.setImageResource(R.drawable.seen);
            image_seen.setVisibility(View.INVISIBLE);
            checkBox_seen.setChecked(seen);
        }else if (callingIntent.getAction().equals(Intent.ACTION_INSERT)){
            seekbar.setProgress(rate);
            image_seen.setImageResource(R.drawable.seen);
            image_seen.setVisibility(View.INVISIBLE);
            checkBox_seen.setChecked(seen);
        }


    }

onSave: onSave:

@Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);


        if (rate != 0){
            outState.putInt("rate", rate);
        }
        outState.putBoolean("check_box", seen);

onRestrore: onRestrore:

@Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);

        seen = savedInstanceState.getBoolean("check_box");
        rate = savedInstanceState.getInt("rate");
       checkBox_seen.setChecked(seen);
       seekbar.setProgress(rate);

    }

尝试禁用对Activity的重新创建,将android:configChanges="orientation|screenSize"到清单文件中的Activity中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android-处理屏幕方向更改对话框 - Android - Dealing with a Dialog on Screen Orientation change Android VideoView-更改屏幕方向后保持宽高比 - Android VideoView - maintaining aspect-fill after a screen orientation change Android:在屏幕方向更改时保存应用程序状态 - Android : Save application state on screen orientation change Android Marshmallow 中屏幕方向更改时的权限对话框使应用程序崩溃 - Permission Dialog while Screen Orientation change in Android Marshmallow crashing the App Android:拉伸对话框片段布局,说“适应屏幕方向”更改 - Android: Stretch the dialog fragment layout say Fit To Screen on Orientation change 当多个加载程序与加载程序管理器一起使用时,android无法在方向更改时保持正确的加载程序状态 - android not maintaining the correct loader state on orientation change when multiple loaders are used with loader manager 自定义Android对话框方向更改 - Custom Android Dialog orientation change 如何在方向更改时保留datetime对话框的状态? - How to retained the state of datetime Dialog on orientation change? 屏幕方向改变时,不得忽略对话框 - Dialog must not be dismiss when screen orientation change 屏幕方向更改后关闭对话框 - Dismiss dialog after screen orientation change
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM