I have a line counter for the user in my notepad app. However, when the app is in landscape vs portrait, the amount of text in the EditText
takes up less space, thus, less lines; so the line count has to update when rotated.
Here is what I did to solve that problem:
I added the following method to my class, and I added this to my activity in my manifest: android:configChanges="orientation|screenSize"
I've tested it and it is going through the method when the screen is rotated.
@Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
TextView linesDisplay = (TextView)findViewById(R.id.linesDisplay);
EditText editText = (EditText)findViewById(R.id.editText);
editText.setText("" + editText.getText().toString()); // this was just a test to see if the Edit Text needed to be "internally constructed"
linesDisplay.setText("Lines: " + editText.getLineCount());
}
I wrote 5 lines in portrait, and it displayed "Lines: 5" just fine. Then, when I rotated to landscape, it stayed at "Lines: 5" (when it was actually 4 lines on landscape). Rotated again back to portrait, now it went to "Lines: 4". Again, back to landscape, it went to "Lines: 5".
It seems that every time I rotate, it displays the number of lines in the orientation before it. That is, it will display portrait # of lines when rotated to landscape, then landscapes # of lines when rotated back to portrait, and so on.
P --> "Lines: 5" (correct)
L --> "Lines: 5" (should be 4)
P --> "Lines: 4" (should be 5)
L --> "Lines: 5" (should be 4)
...
^ it works the same vice versa, like if I start in landscape and keep rotating back it forth, it will be one behind (after the first rotation), just like the situation above.
Any help? I assume it's because it's running through my code before it actually rotates, so the line count is behind what it should be. Is there any way to run my code after it's sure that the screen is fully rotated?