How to auto scroll to input field when using a RecyclerView - android

When the keyboard appears the RecyclerView doesn't automatically scroll to the position of the selected input field. So the keyboard gets over the selected field.
I tried to add android:windowSoftInputMode="stateVisible|adjustResize" to the activity as suggested in other questions but no luck.

Which layout manager are you using? There is a bug fix about this, but should work in most cases. The bugfix will be released in the next one or after :/, meanwhile, it might work to call scrollToPosition(clickedItemPosition) when keyboard comes up. (TextView focus)

Related

Edit text weird behavior

I have an ExpandableListView which contains a RecyclerView of a custom layout. This layout contains some views including my EditText.
My behavior is : When I click in my number EditText, the keyboard appears for about 0.5s, the whole layout is cleared with default values, then the keyboard disappears, a text EditText appears, and finally I loose focus. When I click on it one more time, the keyboard stays, but in text type. Strange thing : the problem seems to be only on devices where the whole layout overflows the screen because on 10" tablet, everything is ok (layout not cleared, and keyboard not disappearing).
According to me, when I get the focus in the EditText, the layout is re-creates , making it to be cleared.
I tried a long time to figure out what was going on, but I didn't find anything. Here is the things I tried, but didn't change anything :
android:descendantFocusability="beforeDescendants" // on all parent of the EditText
focusable="true" // On the EditText
android:windowSoftInputMode="adjustPan" // In the activity in the manifest
making all the ViewHolder attributes final
As the code is very huge for all that amount of things, I don't know what I should post to help. So don't hesitate to ask anything if it can help
Thanks!
EDIT : A Gif showing the issue https://imgur.com/a/BPue4
Try adding this line to your activity on manifest.xml:
android:configChanges="keyboardHidden|screenSize"
Opening keyboard or screen size changes may trigger to re-create your content.

Android's EditText not receiving keyboard input correctly

Just found myself trying to figure out this strange behavior in for EditText.
Information:
Bug seems to only happen in some devices! for now I've only seen it in Sony Xperia D2303.
App description:
I'm working on an app that has a main activity and navigation is done trough different fragments that are replaced as user moves from one section to another.
At one point I'm showing a DialogFragment with an edit text field, with background set to #null, with a hint text. (I have also tried with a normal edit text, taken from widget list and dragged to the layout and found the same behavior).
Problem:
When clicking on the EditText, software keyboard SHOWS UP but when typing there is no letter input in the EditText! I can long press, to visualize cursor position marker and also the magnifying glass shows up.
Things I've tried:
- I've tried requesting focus with xml, programmatically.
- Setting touchable(in touch mode also)
- Setting descendantFocusability attribute of parent to 'afterDescendants'
- Overriding onTouchListener and showing keyboard programmatically through the InputManager and using the edit text's token
… and maybe other things which I don't remember
There is but a workaround that I've found!!! sending the app to background, and bringing it to foreground again… so it seems something related to focus maybe?? but then why does keyboard show up, and cursor marker and magnifying glass work?
This solution does not work for me as it depends on the user taking action
Has anyone found this problem? any suggestions?
Thanks in advance!

How to trigger the horizontal orientation keyboard?

Context:
I have a small EditText field in my Activity, and it needs to be small because there is a lot of another View's on this Activity. But the content most of times are very long, and the user have a bad experience typing long texts into a small field.
Question:
How i can always show the "Horizontal Keyboard" when the user click on the EditText, even if the user are at Vertical Orientation(portrait) ?
Example:
Here is a screenshot of the "Horizontal Keyboard" that i'm talking about:
Important:
Setting the orientation to horizontal, is not really necessary. If this same keyboard shown on the image above can be triggered even if you are using vertical orientation, it would be useful too.
Sorry, I don't have 50 reputation points for commenting. But this link is for a question where OP is trying to disable the full screen keyboard. Perhaps if it's possible to disable, probably you are able to force enable it.
Disabling the fullscreen editing view for soft keyboard input in landscape?
EDIT:
So, searching a little more, I came to the conclusion that you can't force the keyboard to enter in fullscreen mode. Unless you make a keyboard app of your own that works only in fullscreen. But still would need the user to activate it on the settings menu.
Anyway, I found this solution by a user: force fullscreen on edittext in android, the answer suggests creating an Activity just for writing (an Activity with only an EditText as it's layout). And calling this Activity with the startActivityForResult method. Thus returning the text entered by the user and placing it on the respective EditText (or whatever widget you are going to use for the text).
Again, hope it helps.

Android Edit Text Cursor Doesn't Appear

in my app I disabled the keyboard (I use now my custom keyboard) using this code:
editText.setInputType(InputType.TYPE_NULL);
Now, my problem is that the text cursor does not appear anymore in the edit text. What should I do? Any suggestion would be very appreciated.
There is an Issue opened in bug tracker Issue opened in bug tracker for this.
One of the users suggests the approach which works on "most" devices.
Briefly, all you have to do is call:
editText.setRawInputType(InputType.TYPE_CLASS_TEXT);
for your EditText view (after you called editText.setInputType(InputType.TYPE_NULL);).
You should probably also set:
editText.setTextIsSelectable(true);
in order for text to be selectable (though in does not seem to work properly with Samsung Galaxy SIII). This method is only available starting from HONEYCOMB (api11) so keep that in mind when developing for older Android versions.
Also it is stated that your EditText should not be the first view to receive focus when activity starts (if it is - just requestFocus() from another view). Though I (personally) have not experienced any problems with this.
Rather than just using a custom view for your custom keyboard, why not implement a full-fledged IME? That will solve your cursor problem, and even make your keyboard available outside your app (if you want).
This answer has a couple useful links if you want to do that:
How to develop a soft keyboard for Android?
I really wouldn't suggest this. Writing a good full fledged IME is really hard. In addition, users come to expect functionality from their keyboard (auto-correct, Swyping, next word prediction, the ability to change languages) that you won't have unless you spend months on the keyboard itself. Any app that wouldn't allow me to use Swype would immediately be removed (bias note: I worked on Swype android).
But if you want to integrate fully with the OS as a keyboard, you're going to have to write an InputMethodService. Your keyboard would then be selectable by the user in the keyboard select menu, and usable for any app. That's the only way to get full OS integration, otherwise you'll need to really start from scratch- writing your own EditView. Have fun with that, getting one that looks nice is decidedly non-trivial.
Also, setting input type null won't disable most keyboards. It just puts them into dumb mode and turns off things like prediction.
I tried the below answer and it worked, but take care that
1) EditText must not be focused on initialization
2) when your orientation changes while the user's focus is on the editText, the stock keyboard pops up, which is another "solvable" problem.
This was mentioned in a previous answer but take care that you MUST make sure your editText element do not get focus on instantiation:
https://code.google.com/p/android/issues/detail?id=27609#c7
#7 nyphb...#gmail.com
I have finally found a (for me) working solution to this.
First part (in onCreate):
mText.setInputType(InputType.TYPE_NULL);
if (android.os.Build.VERSION.SDK_INT >= 11 /*android.os.Build.VERSION_CODES.HONEYCOMB*/) {
// this fakes the TextView (which actually handles cursor drawing)
// into drawing the cursor even though you've disabled soft input
// with TYPE_NULL
mText.setRawInputType(InputType.TYPE_CLASS_TEXT);
}
In addition, android:textIsSelectable needs to be set to true (or set in onCreate) and the EditText must not be focused on initialization. If your EditText is the first focusable View (which it was in my case), you can work around this by putting this just above it:
<LinearLayout
android:layout_width="0px"
android:layout_height="0px"
android:focusable="true"
android:focusableInTouchMode="true" >
<requestFocus />
</LinearLayout>

Keyboard issues arising on orientation change

In my app I am using various edit text and text view and list view.
Now my problem is my keyboard appears again on orientation change. Ideally when user minimize the keyboard, it should be in minimized state when device is tilted. But it reappears. How do we handle this situation.
My other problem is one of my edit text is some what at the end of screen. When keyboard appears, it hides the edit text. so user is not able to see what he is typing. What is the ideal way to handle this.
thanks.
Solution to all problem is this line android:windowSoftInputMode="stateUnchanged|adjustResize"
"stateUnchanged" will make the state of keyboard same as it was in earlier state. Either hidden or visible.
"adjustResize" will make your edit text visible.
Hope this helps.!!!
Edit
This need to be added in android manifest file.
I had this same problem. To keep the keyboard from re-appearing on rotation when you have TextViews, you must do 2 things-
Make sure the TextView doesn't have the focus. Even after hiding the keyboard, a TextView can still be focused. Try calling
textView.clearFocus()
and you should be able to see the difference in the TextView.
Make sure there is another view before it (like a parent LinearLayout, or even just a LinearLayout with 0 width and 0 height) which has these properties-
android:focusable="true"
android:focusableInTouchMode="true"
Try adding this code in your Activities properties in the manifest
android:windowSoftInputMode="stateHidden|adjustPan"
Like
<activity
android:name=".MyActivity"
android:windowSoftInputMode="stateHidden|adjustPan" >
This should take care of both your problems
For the Second Question :
You can set your layout to ScrollView to avoid hiding of edittext on Keyboard appears.
Put your entire layout in a ScrollView.
I found the following documentation to be helpful in understanding the various flags associated with the soft keyboard:
https://developer.android.com/guide/topics/manifest/activity-element.html#wsoft

Categories

Resources