android - handle virtual keyboard enter key behaviour - android

I have five edittext in my layout. by default when i click on any of the edittext the virtual keyboard shows like following
Is it possible to modify the behavior of enter key ? I want when the key pressed the focus should be transferred to next edit text. Keyboard should look like
notice the change in enter key and also suggestions are disabled. Is there any way to achieve it ?

To disable text suggestions, add the following parameter to your EditText:
<EditText
android:inputType="textNoSuggestions"
(…)
/>
And to go to the next field upon pressing "enter" add the ID of the next field on the following parameter:
<EditText
android:nextFocusForward="#+id/nextEditTextId"
(…)
/>
Details can be found here.
Hope it helps!

Related

how to get whole text selected onClick EditText

In a browser we click on search box whole text got selected. like that how to enable this in android EditText. When click on EditText, whole text in it got selected.
Its my first question so please don't critic it.
editText.setSelectAllOnFocus(true);
You can add it in EditText
android:selectAllOnFocus="true"
Use android:selectAllOnFocus
If the text is selectable, select it all when the view takes focus.
May be a boolean value, such as "true" or "false".
From XML
android:selectAllOnFocus="true"
FROM java
YourEditText.setSelectAllOnFocus(true);

Change "Done" button in Android numeric keyboard

I have an EditText in Android configured for the number keyboard, and I would like the keyboard's button to say "next", while mine is saying "done".
How can I change that?
I already tried:
<com.innovattic.font.FontEditText
style="#style/CadastroTextBoxStyle"
android:hint="CEP"
android:id="#+id/etCEP"
android:inputType="number"
android:singleLine="true"
android.imeOptions="actionNext" />
And also this:
etCEP.setImeActionLabel("Next", KeyEvent.KEYCODE_ENTER);
But it still says done.
What else can I do?
Thanks
As can be seen in Specifying the Input Method Type, you do not need to call TextView.setImeActionLabel(CharSequence, int) and you have to instead just provide a android:imeOptions value such as actionSend or actionNext in XML attributes to change the label accordingly.
This is not working for you because you have mistyped : as . in your attributes. Switching those out should fix your issue in no time.

How to allow Multiline Text in Android EditText while restricting input using android:digits?

With an EditText it is possible to add an entry to support alphanumeric digits like the following:
android:digits="#string/alphanumeric_allowed_chars_free_textentry"
Where the string is defined as
<string name="alphanumeric_allowed_chars_free_textentry">
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-=[];,./~!##$%^</string>
However, as others have noted, when a user sets the digits attribute, it can cause the "enter" button to show a return arrow instead of a next or done button, as described in this related question
The typical solution to get done to show up is to set android:singleLine="true" and android:imeOptions="actionDone", but this will only work for an input box which is not a multi-line box. I have a multi-line edit text and would like to be able to add a done button and also fliter using the digits attribute.
Does anyone know how to allow an EditText to use digits while also being multiline, while also allowing the return button to show "done"? Android 4.4
What if you modify alphanumeric_allowed_chars_free_textentry to include carriage return (\r, \n)?
i was unable to reply / comment to your comment
So added new answer
in multiline edittext
after adding \r\n to my digits property
android:digits="1234567890#$%^&*()_+-=qwertyuiopasdfghjklzxcvbnm:;,.?/|~`{}[]QWERTYUIOPASDFGHJKLZXCVBNM+x÷x€£¥₩×\r\n ●■□⊙☆¤•°《》¿¡\"
i am able to goto nextline on enter as well using the digits property.
below is my axml code "
i was unable to reply / comment to your comment
in multiline edittext after adding \r\n to my digits property android:digits="1234567890#$%^&*()_+-=qwertyuiopasdfghjklzxcvbnm:;,.?/|~`{}[]QWERTYUIOPASDFGHJKLZXCVBNM+x÷x€£¥₩×\r\n ●■□⊙☆¤•°《》¿¡\"
i am able to goto nextline as well using the digits property .
"
<EditText
android:id="#+id/NewTask_TaskDescription"
style="#style/MultiLineTextboxStyle"
android:layout_marginBottom="10dp"
android:layout_height="151dp"
android:layout_width="match_parent"
android:inputType="textCapSentences|textMultiLine"
android:singleLine="false"
android:digits="1234567890#$%^&*()_+-=qwertyuiopasdfghjklzxcvbnm:;,.?/|~`{}[]QWERTYUIOPASDFGHJKLZXCVBNM+x÷x€£¥₩×\r\n ●■□⊙☆¤•°《》¿¡\\" />
"

how to NOT select all on EditText long click

When the user long-touches/long-clicks in the EditText, my app always selects all text. How do you instead make the EditText not select all, and instead select only the user-selected text?
I read Select all text inside EditText when it gets focus
then tried explicitly setting android:selectAllOnFocus="false"but that is not working. Double tapping or any other click length doesn't work either.
To override OnLongClickListener might work, but I don't know how to get the user's start and end selected index.
For those who are coming across this question in the future, the (or at least a) solution is to add the textLongMessage option to android:inputType:
<EditText
...
android:inputType="textLongMessage" >
<!-- Or you might have multiple input types -->
<EditText
...
android:inputType="textLongMessage|textMultiLine|textNoSuggestions" >
This will make the EditText's behavior be to select a single word from the text.
Try reading these liknks and see if they help:
how to NOT select all on EditText long click
how to NOT select all on EditText long click
You can try in your main.xml file:
android:selectAllOnFocus="true"

How to set first alphabet is in upper case by default in android

I want to fill a form where Name,Address,City,some fields are there.How can I set that if user enter first name or something another field then first letter should be in caps by default in android.please help me.
thank you
You can easily set the inputType on your EditText:
<!-- in your xml -->
android:inputType="textCapSentences"
or
//(programmatically)
yourEditText.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
Here the documentation.

Categories

Resources