View in scrollview gets hidden when requestFocus() is called - android

I have a ScrollView where there are a number of EditText fields.
When i call requestFocus() on any of those fields, the EditText fields comes into view as the scroll view scrolls by itself, even when the soft keyboard is up.
The problem lies in the fact that i have had to add a separate view above the soft keyboard to accommodate a clear button, and it is that custom view that is hiding the edit text field in focus.
Now, i have to manually scroll the scroll view to see the edit text field in focus.
Please help me to show the edit text field in focus above the custom view which is placed on top of the soft keyboard.
Is there any way to do so ?
EDIT:: This is how i solved this problem.
scrollView.post(new Runnable() {
public void run() {
scrollView.scrollTo(0, scrollView.getBottom()-200);
}
});
and gradually went on decreasing the amount i am subtracting from the scrollView.getBottom() call. This worked fine for me.

In your manifest.xml file, for your activity just add this line:
android:windowSoftInputMode="adjustPan"

Related

How to hide soft keyboard from fragment

I have a fragment with multiple linear layouts and one edit text box. However the keyboard stays open all the time. I've tried setting the fragment main layout as clickable and focusableInTouchMode which works but only for parts of the view that show the main layout. Any other parts of the view that are touched still do not hide the keyboard.
Does anyone know how I can overcome this without adding focus listeners to all parts of the layout?
Have you tried to set:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

Soft keypad popsup and hides slowly in fragment and makes typing sluggish

I am using [SlidingMenu][1] in my app. I use Viewpager to show three fragments in tabs in a fragment. Three fragments have EditTexts inside LinearLayouts which are in ScrollView. So My XML XMl is like this:
RelativeLayout>ScrollView>LinearLayout>EditText .
After focus is changed to each EditText, typing starts very slowly(takes 1-2 secs to respond). I thought it's because of Soft keypad that tries to resize or pan everytime. So I tried all possible values for windowSoftInputMode. Nothing works. I used same XML in an Activity, where typing is very smooth. Also after typing is done(when user clicks IME done button), keypad hiding is very very slow(takes 3 secs). What could be the problem? and any workaround to avoid?
By the way, I don't have any TextWatchers set for EditTexts.
Edit:
When I remove EditTexts from other two fragments, it's smooth. But only when all the three fragments have EditTexts, it's sluggish.
I avoided this by adding android:windowSoftInputMode="adjustNothing" which does no resizing and no scrolling. And added Focus listeners to edit texts which are at the bottom part of the screen so that they get visible to the users while typing.
editText.setOnFocusChangeListener(new OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
scroll.scrollTo(rootView.getWidth(), rootView.getHeight()); //rootView is my parentView of the fragment
}
}
});
However, if anyone knows an elegant solution, please post it.

EditText loses focus after resizing ListView when keyboard is displayed

I have a ListView that I need to manually resize when the keyboard is displayed.
This works by overwriting the onSizeChanged method and changing the size of the view accordingly. (Thanks to this post How to set size and layout in onSizeChanged?)
However, when the size of the list view is changed the EditText that I clicked on loses its focus and I can't enter any text.
EDIT:
I tried to set the focus of the EditText that had the focus before, however, this doesn't always work, although the method returns true when calling request focus
In onSizeChanged() after resizing the ListView add this line.
editText.requestFocus();
Use edittext.requestfocus() method:
requestFocus();

ScrollView steals focus when scrolling

I am trying to make a chatting window.
There's a TextView wrapped in a ScrollView in the upper side of the screen; and a EditText in the bottom of the screen.
I use following code to make the ScrollView scroll automatically when the new message is out of view.
scroll.post(new Runnable(){
#Override
public void run() {
scroll.fullScroll(View.FOCUS_DOWN);
}
});
Something annoying is when the ScrollView scrolls, it steals my focus from the EditText.
I can't input my message when the ScrollView is scrolling.
Can anybody give me some light? Thanks a lot : )
I know a workaround. Call requestFocus on the view that should keep the focus.
It would be nice to know if you solved it in a better way.

When do Android EditText's requestFocus()

I have a number of EditTexts inside a scrollview. In the background these fields are linked to a number of other fields and regularly (once a second or so) the layout has it's textfields updated depending on the values in the EditText.
The problem is if one EditText has focus at the top of the ScrollView and the user scrolls the view done (i.e. so the focused EditText is off screen), but if the update is made to the views, the scroll view moves up to focus on the EditText at the top of the view.
The closest I have got to remedying this is to make the scroll view change focus when scrolling however this is still has the same behaviour but at a reduced scale.
Does anyone have an idea of how I can stop this from happening?
Cheers,
Matt
You can try using EditText#setFocusable around your code that updates the value. I haven't tested this but if the problem is that it is getting focus when you use setText() it may help.

Categories

Resources