[英]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.