我m having trouble with maintaining the dialog on orientation change.
I
使用onSaveInstanceState,onRestoreInstanceState。
但我在onRestore上有一个null。我想让对话框在我改变屏幕方向时显示相同的值。
感谢名单!
这是对话框:
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:
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
if (rate != 0){
outState.putInt("rate", rate);
}
outState.putBoolean("check_box", seen);
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);
}
答案 0 :(得分:0)
尝试禁用重新创建活动,将android:configChanges="orientation|screenSize"
添加到清单文件中的活动。