2

I have a simple MainActivity where an orientation change from portrait to landscape and back to portrait works properly. My SecondActivity screen has a TextView with EditText line for user input. Unfortunately, on orientation change from portrait to landscape, the layout does not change properly. It appears to not carry over to the landscape mode. The TextViews, background colors and toolbar of the layout file are not loading. Only the EditText hint shows and the background shown is white color. I tested on a Samsung Galaxy S3 and a Genymotion emulator with the same bad result. Lastly, when the device or the emulator is rotated back to portrait, the view layout loads correctly...everything displays properly like the original portrait display. What am I missing here?

SecondActivity java file:

...
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.cardviewinput);

EditText java file:

public class ListenerEditText extends EditText {    
...

Layout xml file:

...
<LinearLayout

    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_weight="1"
    android:background="#FF0000" >

    <TextView
        android:id="@+id/createSkycard"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textColor="#FFFFFF"
        android:layout_marginTop="20dp"
        android:gravity="center_horizontal"
        android:text="Create a skycard"
        android:textAppearance="?android:attr/textAppearanceMedium"/>


</LinearLayout>


<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_weight="1"
    android:background="#FF0000"        >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#FFFFFF"
        android:text=" To Do item:  "
        android:textAppearance="?android:attr/textAppearanceMedium"/>

<com.example.jdw.secondscreen.ListenerEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/CEditText"
        android:inputType="text|textCapSentences|textNoSuggestions"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:hint="Type a new item here"
        android:textColor="#000000"
        android:singleLine="true"
        android:imeOptions="actionNext" >

        <requestFocus />
    </com.example.jdw.secondscreen.ListenerEditText>
...
Stefan
  • 5,203
  • 8
  • 27
  • 51
AJW
  • 1,578
  • 3
  • 36
  • 77

1 Answers1

0

Be sure that in the moment of the orientation change, your cursor is not inside the edittext. It sounds to me that your activity is loading with the cursor already set to start typing, so when you change the orientation, you are only seeing the inside of the EditText with the hint and ready to type something.

Now if you want it to behave this way, is up to you.

joaortk
  • 73
  • 1
  • 9
  • 1
    You can disable this as shown in this post: http://stackoverflow.com/questions/4336762/disabling-the-fullscreen-editing-view-for-soft-keyboard-input-in-landscape – joaortk May 29 '15 at 03:50
  • I think you are correct, the activity is loading with the cursor still in the EditText and I am only seeing the EditText with the hint. However, I do want to re-load the full layout though, even if the cursor is still in the EditText. This would occur if the user started typing something that would then show on the EditText line and then the user decides to change the orientation and then finish typing on that EditText line. I'm wondering if the code in the EditText is casuing problems here. Any thoughts? – AJW May 29 '15 at 03:55
  • I'm not sure if I got what you want to accomplish, but to me you have two options: Force the Edittext to lose the focus, or try the solution I posted in the previous comment, showing how to disable the fullscreen edittext. – joaortk May 29 '15 at 03:59
  • Removing the line did not change anything. joaortk: let me know if you have a few minutes and I will post two screenshots to show you what I am seeing... – AJW May 29 '15 at 04:03
  • Did you try changing the android:imeOptions, from "actionNext" to "android:imeOptions="flagNoExtractUi" ? – joaortk May 29 '15 at 04:22
  • I am out of ideas for now... maybe it has something to do with your implementation of the ListenerEditText, but without looking at the code, it is just guessing. Maybe if you try the same code using regular EditText it can give you some new path to follow. – joaortk May 29 '15 at 05:11