EditText doesn't show when I have focus in another - android

I have a layout where i have one image view, two edittext and one button,
when i clicked on the first edittext, i can't scroll to the second to fill it too, because of the virtual keyboard, here is my code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal" >
<ImageView
android:id="#+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:src="#drawable/logo"
android:contentDescription="#string/invokeme" />
<EditText
android:id="#+id/login"
android:layout_height="wrap_content"
android:layout_width="235dip"
android:ems="10"
android:layout_marginTop="25dp"
android:layout_below="#id/logo"
android:hint="#string/login" />
<EditText
android:id="#+id/password"
android:inputType="textPassword"
android:layout_height="wrap_content"
android:layout_width="235dip"
android:ems="10"
android:layout_marginTop="5dp"
android:layout_below="#id/login"
android:hint="#string/password" />
<Button
android:id="#+id/submitLogin"
android:layout_width="235dip"
android:layout_height="wrap_content"
android:ems="12"
android:text="#string/login"
android:layout_below="#id/password"/>
</RelativeLayout>

There might be more than one way around. First one may be that you can keep everything ( the whole relative layout) inside a ScrollView. Second way can be that you may establish a touch listener on your view, excluding the two EditText's. When anything other than those two EditText is touched, you can hide the keyboard from the screen. See How to hide soft keyboard on android after clicking outside EditText? for more. Hope it helps.

Related

All my EditTexts in my app has a delay (short freeze) when clicking them before I can type

In my app I'm using EditText in a few different places. However, whenever I click any of these EditText's, the soft keyboard appears and then there is a short delay where it seems like everything freezes for about one or two seconds before I can type.
Same thing happens when I am done typing and click the back button, the soft keyboard disappears and then there is a white square instead where it took place and it again freezes for one or two seconds.
I have searched for it and I found this, I tried it but didn't change anything. What can be the cause for this and how can I fix it?
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:id="#+id/weekTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:textColor="#color/PaleBlack"/>
<RelativeLayout
android:id="#+id/desiredHoursContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="#id/weekTextView"
android:layout_toRightOf="#+id/weekTextView">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/desiredHoursEditText"
android:layout_toStartOf="#id/desiredHoursEditText"
android:paddingEnd="5dp"
android:paddingRight="5dp"
android:text="#string/desired_hours"
android:textColor="#color/PaleBlack"/>
<EditText
android:id="#+id/desiredHoursEditText"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_toLeftOf="#+id/unitTextView"
android:layout_toStartOf="#+id/unitTextView"
android:background="#drawable/main_border_square"
android:inputType="number"
android:maxLength="2"
android:minWidth="40dp"
android:textAlignment="center"
android:textColor="#color/PaleBlack"/>
<TextView
android:id="#+id/unitTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:paddingLeft="5dp"
android:paddingStart="5dp"
android:text="h"
android:textColor="#color/PaleBlack"/>
</RelativeLayout>
I fixed it by adding the following line to my activity in the manifest, not sure why tho.
android:windowSoftInputMode="adjustNothing"

RelativeLayout is not Scrollable in ScrollView

Any idea why the following layout is not scrollable? I have a RelativeLayout in a ScrollView. The Views fit on the screen. however they are covered whenever the keyboard pops up. I want to make the screen scrollable when the keyboard pops up, because it covers the Login and password EditBoxes so it is har to see what someone is typing
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<com.alarm.alarmmobile.android.view.RobotoLightTextView
android:id="#+id/passcode_login_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="20dp"
android:text="#string/passcode_login_body"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText
android:id="#+id/passcode_login_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/passcode_login_text"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="20dp"
android:hint="#string/login_textview_username"
android:singleLine="true" />
<EditText
android:id="#+id/passcode_login_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/passcode_login_username"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:hint="#string/login_textview_password"
android:inputType="textPassword"
android:singleLine="true" />
<com.alarm.alarmmobile.android.view.RobotoLightButton
android:id="#+id/passcode_login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/passcode_login_password"
android:layout_marginRight="16dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:text="#string/login_button_login" />
</RelativeLayout>
</ScrollView>
On the activity or fragment class of this layout you have to call this:
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
Include this in your Manifest:
<activity android:name="..." // your activity here
....
android:windowSoftInputMode="adjustResize|adjustPan">
/>
NOTE: Not sure if adding adjustPan will cause the problem to come up again or not.
If everything can fit on the screen, the ScrollView will not be able to scroll anywhere. If there is a component that is not fully visible then the scroll should be available to see the rest of the component. Without being able to see what the problem is it's hard to find the exact solution.

android - EditText height resize based on keyboard

I am having an activity in android where there is an editbox and 3 buttons below the editbox. Please see attachment. When this activity is launched, the default state is STATE1.(Please see image). The keyboard is visible by default. Now when I press the back button or dispose the keyboard, I wish to have the edittext resized and occupy the whole screen as shown in STATE2.
I am not sure how to accomplish this. I have the height of the edittext hardcoded to some dp based on the target device. I believe this has to be changed. Can anyone help me in how to accomplish this.
The XML of the layout file is below as well as the screencap
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<EditText
android:id="#+id/EditMessage"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:background="#drawable/newback"
android:gravity="top"
android:imeOptions="actionDone"
android:inputType="textMultiLine|textFilter|textVisiblePassword|textNoSuggestions"
android:maxLength="200"
android:padding="5dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="#+id/PostMessage"
android:layout_width="0dp"
android:layout_height="45dp"
android:layout_weight="1"
android:layout_marginRight="0.2dp"
android:background="#drawable/newbutton_corner"
android:text="#string/SubmitMessage"
android:textColor="#FFFFFF"
android:textStyle="bold" />
<Button
android:id="#+id/CancelMessage"
android:layout_width="0dp"
android:layout_height="45dp"
android:layout_weight="1"
android:layout_marginRight="0.2dp"
android:background="#drawable/newbutton_corner"
android:text="#string/CancelMessage"
android:textColor="#FFFFFF"
android:textStyle="bold" />
<Button
android:id="#+id/DeleteMessage"
android:layout_width="0dp"
android:layout_height="45dp"
android:layout_weight="1"
android:background="#drawable/newbutton_corner"
android:text="#string/DeleteMessage"
android:textColor="#FFFFFF"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Change your EditText as follows:
<EditText
android:id="#+id/EditMessage"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="top"
android:imeOptions="actionDone"
android:inputType="textMultiLine|textFilter|textVisiblePassword|textNoSuggestions"
android:maxLength="200"
android:padding="5dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
/>
Add layout_weight = 1
In my opinion you do not need adjustPan. I will leave it upon you to decide. The behaviour will be different and you can try it out. Here is what the documentation says about adjustPan:
The activity's main window is not resized to make room for the soft
keyboard. Rather, the contents of the window are automatically panned
so that the current focus is never obscured by the keyboard and users
can always see what they are typing. This is generally less desirable
than resizing, because the user may need to close the soft keyboard to
get at and interact with obscured parts of the window.
Your buttons at the bottom may get hidden if using this. Instead use adjustResize:
Put this line in the activity inside AndroidManifest
android:windowSoftInputMode="stateVisible|adjustResize"
Try this.. in your manifest.
<activity
android:name="Activity"
android:windowSoftInputMode="adjustPan"/>
and your edittext use <requestFocus /> for from that start itself it'll focus
and android:layout_weight="1" it will automatically fill the screen.
<EditText
android:id="#+id/EditMessage"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#696969"
android:gravity="top"
android:imeOptions="actionDone"
android:inputType="textMultiLine|textFilter|textVisiblePassword|textNoSuggestions"
android:maxLength="200"
android:padding="5dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
>
<requestFocus />
</EditText>
Yes you can do that, its simple.
android:windowSoftInputMode="adjustResize" ,, add this attribute to you manifiest under required activity
Set width and height of your text view to match_parent
Done.
add android:windowSoftInputMode="adjustPan" and change android:layout_height="150dp" to android:layout_height="fill_parent"

Scroll a Scroll View which contains Edit Text

my scroll view contains a linear layout which further contains some of the edit text fields. now when I click on a edit text field at the bottom one then soft keyboard appears, but my problem is that it covers that edit textfield. this is my activity declared in android manifest file:
<activity
android:name="me.example.scrollview.LoginActivity"
android:label="#string/title_activity_login"
android:theme="#android:style/Theme.Black.NoTitleBar"
android:windowSoftInputMode="stateHidden|adjustResize|adjustPan" >
</activity>
and here is my layout.xml file for this activity.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/darker_gray"
tools:context=".LoginActivity" >
<ScrollView
android:id="#+id/login_sv_login_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:isScrollContainer="true"
android:background="#android:color/transparent" >
<LinearLayout
android:id="#+id/login_ll_container"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_marginTop="230dp"
android:layout_gravity="center_horizontal"
android:background="#android:color/transparent"
android:orientation="vertical" >
<EditText
android:id="#+id/txt_username"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_gravity="center_horizontal"
android:background="#drawable/rounded_edittext"
android:ems="10"
android:inputType="textEmailAddress"
android:maxLines="1"
android:singleLine="true" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/txt_phone"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="10dp"
android:background="#drawable/rounded_edittext"
android:ems="10"
android:inputType="phone"
android:maxLines="1"
android:singleLine="true" />
<EditText
android:id="#+id/txt_password"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="10dp"
android:background="#drawable/rounded_edittext"
android:ems="10"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true" />
<Button
android:id="#+id/btn_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginTop="10dp"
android:background="#drawable/ic_login"
android:text="" />
</LinearLayout>
</ScrollView>
Now Please help me as I am very new to android programming. I am unable to fix this issue and can't find a way to scroll my scroll view without resizing my main window.I just want my scroll view to make scrolling when soft keyboard appears.Thanx in advance.
Both previously pointed out solutions can work. But there might still be a problem if the edittext is at the bottom of the ListView where it would still be covered by the onscreen keyboard. Not sure if a scrollview can be scrolled to a point where there is no more content.
What i've seen is that you might use two contradicting flags in your manifest:
android:windowSoftInputMode="stateHidden|adjustResize|adjustPan" > </activity>
adjustResize and adjustPan can imho NOT be combined. Try how it looks with only adjustResize. This should avoid that the keyboard covers anything of your view.
You can try:
ScrollView scroll = (ScrollView)findViewById(R.id.scrollview);
scroll.scrollTo(0, sv.getBottom());
or
scroll.scrollTo(5, 10);
You can use YOURSCROLLVIEW.scrollTo(int x, int y) or YOURSCROLLVIEW.smoothScrollTo(int x, int y) to move the scroll view to the appropriate coordinates so that the edit text box and keyboard are both shown.
More information about these functions and other scrollview functions can be found on the android developer reference page.

EditText goes out of the screen sometimes when virtual keyboard shows up

I am developing an application for Android.
I have a simple layout. A CheckBox, a Spinner and a Button at the top, a two line EditText at the Bottom which is displayed when the CheckBox is checked and another EditText which covers the rest of the space in the middle.
The problem is that when I am writing on the big EditText, sometimes the layout goes out of the screen on top and as a result I can't see what I am writing.
As a solution, I can set my layout to resize when the keyboard shows (using android:windowSoftInputMode="adjustResize" on the manifest.xml) but that won't be good since I do not want the 2 EditTexts to share the space left on the screen.
My layout code follows:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button android:id="#+id/button"
android:text="Push"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"/>
<CheckBox android:id="#+id/check_box"
android:text="Check"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true" />
<Spinner android:id="#+id/spinner"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<EditText android:id="#+id/text_2"
android:hint="#string/hint_2"
android:inputType="textMultiLine"
android:maxLines="2"
android:gravity="top"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true"
android:visibility="gone" />
<EditText android:id="#+id/text_1"
android:hint="#string/hint_1"
android:inputType="textMultiLine"
android:gravity="top"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_below="#id/spinner"
android:layout_above="#id/text_2"
android:layout_alignWithParentIfMissing="true" />
</RelativeLayout>
P.S. This thing happens only on my Wildfire and very rare on the Emulator. A friend's Desire HD didn't have any problem at all. I don;t know if this makes any difference...
Thanks in advance for your help.
Antonis
I have the exact same problem. I've tested and this only happens with EditText in multiline mode and when SoftInputMode is set to adjustPan. This is most probably an Android bug.
The only solution I've found is to remove adjustPan.

Categories

Resources