これが私の主な活動です
public static boolean popupStatus=false;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
if (savedInstanceState != null){
popupStatus = savedInstanceState.getBoolean("Open");
}
setContentView(R.layout.main);
public void onSaveInstanceState(Bundle savedInstanceState) {
savedInstanceState.putBoolean("Open", DateTimePicker.openPopup);
super.onSaveInstanceState(savedInstanceState);
}
DateTimePicker.java
1 つのボタンと 1 つの Textviewを持つクラスがあります。ボタンをクリックすると、別のクラスCalendar.java
が PopupWindow に取り込まれ、このポップアップ ウィンドウに my class が表示されますCalendar.java
。Calendar.java
縦向きモードと横向きモード用にクラスの異なるレイアウトを作成しました。DateTimePicker.java
コードの一部を次に示します。
public static boolean openPopup = false;
textView = new TextView(this.getContext());
this.addView(textView, layoutParams);
button = new Button(this.getContext());
button.setText("C");
this.addView(button, layoutParams1);
button.setOnClickListener(this);
if(Main.popupStatus){
button.performClick();
}
public void onClick(View v) {
if(Main.popupStatus){
new Handler().postDelayed(new Runnable() {
public void run() {
openCalendar();
}
}, 100);
}
else{
openCalendar();
}
private void openCalendar() {
Calendar calendar = new Calendar(this.getContext());
if(portrait.equals(orientation)){
pw = new PopupWindow(calendarLayout, 245, 284, true);
}
else{
pw = new PopupWindow(calendarLayout, 295, 240, true);
}
pw.setOutsideTouchable(false);
pw.showAtLocation(this, Gravity.NO_GRAVITY, 10, 80);
openPopup = true;
}
public void closeCalendar(){
pw.dismiss();
openPopup = false;
}
Main.XML が含まれていますDateTimePicker
。実際には、実行時に方向が変更された場合でもポップアップウィンドウを開く必要があったため、メソッドでフラグを設定openPopup = true;
しopenCalendar()
て実行しました。実行時に開いて方向が変更された場合、このフラグはメソッドに保存されonSaveInstanceState()
ます。向きが変更された後、チェックインさonCreate()
れ、それぞれの向きモードのポップアップが開きます。あなたが私の主張を理解してくれることを願っています。
問題:最初にポートレート モードでボタンをクリックすると、ポートレート レイアウトのポップアップ ウィンドウが表示されます。次に、ポップアップ ウィンドウを閉じずに、向きを横向きに変更します。そして、変更後、ポップアップウィンドウがそのまま表示され、横向きレイアウトの画面に表示されます。今までは問題なく動作しています。しかし、横向きモードで IF ポップアップ ウィンドウが開かれ、向きを縦向きに変更すると、縦向きレイアウトのポップアップ ウィンドウが表示されず、FORCE CLOSE メッセージが表示されます。ヒント。皆様には大変感謝しております。ありがとう!
PS:向きを変更するということは、ctrl+F11 を押してエミュレータの向きを変更することを意味します。