我在ViewSwitche
中有一个FragmentActivity
r,包含2个布局文件,每个方向一个。 ViewSwitcher
由radio group
控制。
当我旋转屏幕时,一切都像我期望的那样,正确的布局文件用于渲染屏幕。
但是,当屏幕旋转时会触发广播组的 如何在onCheckedChanged
事件。
该侦听器看起来像这样(在onCreate
中创建):< / p>
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//snip
radios.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int index) {
viewSwitcher.showNext();
}
});
}
listener
中调用 viewSwitcher.showNext(),而不会在屏幕旋转时触发它?
答案 0 :(得分:0)
private boolean wasRotatedHack;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.savedInstanceState = savedInstanceState;
if (savedInstanceState == null) {
wasRotatedHack = false;
} else {
wasRotatedHack = true;
}
tabRadios.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int index) {
if (!wasRotatedHack) {
viewSwitcher.showNext();
} else {
wasRotatedHack = false;
}
}
});
startInspectionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(getApplicationContext(), InspectionActivity.class));
}
});
}