を使用していPopupWindow
ます。PopupWindow
画面の向きが変わると破壊されるという問題に直面しています。
画面の向きの変更時に破壊しないようにする必要があります。
これをこのアクティビティに設定しました。
<activity
android:name=".MainPageActivity"
android:configChanges="orientation|keyboardHidden"
android:label="@string/app_name"
android:windowSoftInputMode="adjustPan" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
コード
/**
* Pop up Window
*/
private void initatePopUpWindow() {
try {
LayoutInflater layoutInflator = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = layoutInflator.inflate(R.layout.popup_new_quote, (ViewGroup) findViewById(R.id.popupNewQuote));
displayMetrics = context.getResources().getDisplayMetrics();
display = ((WindowManager) this.getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
if(!(display.getOrientation() == Configuration.ORIENTATION_LANDSCAPE || display.getOrientation() == Configuration.ORIENTATION_UNDEFINED)) {
popupWindow = new PopupWindow(layout, displayMetrics.widthPixels, (int)(displayMetrics.heightPixels * .40f), true);
} else
popupWindow = new PopupWindow(layout, displayMetrics.widthPixels / 2, displayMetrics.heightPixels / 2, true);
popupWindow.setAnimationStyle(R.style.AnimationPopup);
popupWindow.showAtLocation(layout, Gravity.CENTER, 0, 0);
//New Quote and Quote Name TextView
((TextView)layout.findViewById(R.id.newQuoteTextView)).setTypeface(typeFace);
((TextView)layout.findViewById(R.id.quoteNameTextView)).setTypeface(typeFace);
//Quote Name
final EditText quoteName = (EditText)layout.findViewById(R.id.quoteNameEditText);
layout.findViewById(R.id.cancelButton).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//Dismiss the pop up window
popupWindow.dismiss();
}
});
layout.findViewById(R.id.saveButton).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(!quoteName.getText().toString().equals("")) {
Quote quote = new Quote();
quote.setQuoteName(quoteName.getText().toString().trim());
quote.setQuotePercentComplete("0");
quote.setQuoteCreateDate(Helper.getCurrentDate());
DatabaseHandler db = new DatabaseHandler(context);
if(!db.isRecordExist(quoteName.getText().toString())) {
long insertId = db.insertQuote(quote);
db.close();
//Start the activity
Intent intent = new Intent(context, NewQuoteTabActivity.class);
intent.putExtra("create_new_quote", true);
intent.putExtra("quote_name", quoteName.getText().toString());
intent.putExtra("id", insertId);
startActivity(intent);
} else
Toast.makeText(context, getString(R.string.quote_duplicate), Toast.LENGTH_LONG).show();
} else
Toast.makeText(context, context.getString(R.string.enter_quote_name), Toast.LENGTH_LONG).show();
}
});
//Save Button and Cancel Button
((Button)layout.findViewById(R.id.saveButton)).setTypeface(typeFace);
((Button)layout.findViewById(R.id.cancelButton)).setTypeface(typeFace);
} catch(Exception e) {
Log.v(GlobalVars.TAG, "Exeption at::" + e.getMessage());
}
}