Reputation: 1036
I have weird situation with EditText. Situation:
the code:
private EditText enterText;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
enterText = (EditText) findViewById(R.id.enterText);
}
If I comment the line with findViewById, everything is working properly.
Any ideas why this happens?
EDIT: I've double checked and it happens every time, not only if the line I was written about is commented.. :-\
EDIT2: It happens only on first orientation change event. Every next is OK..
Upvotes: 0
Views: 710
Reputation: 1404
Every time you rotate your phone the Activity restarts, which probably calls something that causes your text to be written again somehow. This is part of the OS and a bit annoying, here is that to do.
If you in your manifest add:
android:configChanges="orientation"
to the activity node in which the rotation is done, you'll have to override the onConfigurationChanged.
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setContentView(R.layout.myLayout);
}
Whenever your phone rotates the overriden method will call and you can do a special initialization like ignore the input if there was an input earlier and such. Hope this gets you on the right track!
PS: You can also pipeline the configChanges with different other "values/configs". Such as keyboardHidden and many others.
They are listed on the following link
Upvotes: 1