here is the part of the Action in which the screen orientation changes:
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); et = (EditText) findViewById(R.id.editText1); et.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { Fragment1 dialogFragment = new Fragment1(); dialogFragment.show(getFragmentManager(), null); dialogFragment.setTextDialog(et.getText().toString()); return true; } }); }
Obviously, the dialog that appears inside the dialog box should appear immediately after onLongClick over editText (I know that when the screen orientation changes, the activity restarts, but it should not start normally, like the first time it was created?)
My problem: when I open the dialog at least once and close it, after changing the screen orientation, the dialog box appears on the screen again, for example, if I clicked on editText for a long time.
I do not quite understand why this is happening.
I also add a dialog fragment structure:
public Dialog onCreateDialog(Bundle savedInstanceState) { final Dialog dialog = super.onCreateDialog(savedInstanceState); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); LayoutInflater adbInflater = LayoutInflater.from(getActivity()); View eulaLayout = adbInflater.inflate(R.layout.dialog_crypt, null); Button btn_OK = (Button) eulaLayout.findViewById(R.id.btnOK); dialog.setContentView(eulaLayout); final EditText et = (EditText)eulaLayout.findViewById(R.id.editText2); et.setText(textDialog); if(et.length()>0) { et.setText(et.getText().toString() + " "); } et.setSelection(et.length()); btn_OK.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { textDialog = et.getText().toString(); ((Main)getActivity()).setTextOnEditText(textDialog); dialog.dismiss(); } }); return dialog; }
Thank you for help.
android oncreate android-dialogfragment screen-orientation
Gasta87
source share