Done is not working in softKeyboard in Autocomplete TextView in android - android

I have One AutocompleTextView and I want to make the virtual keyboard disappear when he hits "DONE" at the AutocompleTextView. So far, the buttons "NEXT"/"DONE" do nothing at all. Any ideas?

Add this Property to your AutoCompleteTextView in xml:
android:imeOptions="actionDone"

The following works for all the Views which support imeOptions; for instance EditText, TextView, AutocompleteTextView, etc.
In your xml:
<autocompleteTextView
inputType = "text"
imeOptions = "actionDone"
/>
In Java:
autocomplete = (AutoCompleteTextView) issueDetailView.findViewById(R.id.yourId);
autocomplete.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if(actionId== EditorInfo.IME_ACTION_DONE) {
//do Whatever you Want to do
}
return true;
}
});

Just add the following on yours XML layout file:
android:imeOptions="actionDone"
android:singleLine="true"

Check android:imeOptions attribute.

In my case android:imeOptions only works if i set android:inputType which is
android:inputType="textAutoComplete" android:imeOptions="actionDone"

Related

android:imeOptions not go to the exact next EditText

I have 2 EditText with id (et_1 and et_2) in a layout, and I set
for et_1
android:imeOptions="actionNext",
android:nextFocusForward="#+id/et_2"
when et_1 gets focus and the the software keyboard shows "Next", and when I click "Next", the focus doesn't go to et_2, but to another EditText in another fragment layout. Why is it this way?
How to make the focus go to et_2?
Thanks.
Try changing,
android:nextFocusForward="#+id/et_2"
to
android:nextFocusDown="#+id/et_2"
I hope it helps!
I had the same problem in one of my apps. What I did instead was have a listener in my activity for when "Next" was pressed and then just manually changed the focus. Like this:
final EditText et_1 = (EditText)findViewById(R.id.et_1);
final EditText et_2 = (EditText)findViewById(R.id.et_2);
// listen on the et_1 EditText
et_1.setOnEditorActionListener(new OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if(actionId == EditorInfo.IME_ACTION_NEXT) { // "Next was selected"
et_2.requestFocus(); // focus on et_2
}
return true;
}
});
I realised referencing does not hide the keyboard
android:nextFocusDown="#+id/et_2"
To Hide the Keyboard add actionDone
<EditText
android:id="#+id/editTextEnterAmount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Amount"
android:imeOptions="actionDone"
/>

Android: Change "Done" button text on keyboard

I am new to Android development. Is it possible to change "Done" button's text on keyboard? If yes, how to do that?
EditText input = new EditText(context);
input.setImeOptions(EditorInfo.IME_ACTION_DONE);
input.setImeActionLabel("My Text", EditorInfo.IME_ACTION_DONE);
Alternatively you can do it in the XML
android:imeActionLabel="My Text"
you can set ImeOptions for textview in xml. their are many as per
this
Link for imeOptions
for example various imeOptions..
actionNone IME_ACTION_NONE.
actionGo IME_ACTION_GO.
actionSearch IME_ACTION_SEARCH.
actionSend IME_ACTION_SEND.
actionNext IME_ACTION_NEXT.
android:imeOptions="actionDone"
use like this:
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionGo"
/>
and call this function to use action:
mInstrunctionEditTxt
.setOnEditorActionListener(new OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId,
KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_GO) {
// do what action you want
}
return false;
}
});

Android keyboard next button issue on EditText

I am facing an issue, I have username & password fields on activity, now when I click on username keyboard appears but no next button on it and I cannot move to next Edittext control through keyboard in this case, keyboard displays enter button in it as attached in screenshot which increases its height,
Can anyone guide me what is the solution to this problem (to display next button on edittext)?
My Code
txtUserid = (EditText)findViewById(R.id.txtUserID);
txtUserPasword = (EditText)findViewById(R.id.txtPassword);
txtUserid.setNextFocusDownId(R.id.txtPassword);
txtUserPasword.setNextFocusDownId(R.id.btnLogin);
Add android:singleLine="true" android:nextFocusDown="#+id/textView2" on your xml.
Will show Next key and also focus to the next field.
In your layout, just set the XML attributes android:imeOptions="actionNext" for your first three text boxes and android:imeOptions="actionDone" for the last one.
More Examples
add this lines below your lines of code you provided:
txtUserid.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// If the event is a key-down event on the "enter" button
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER))
{
// Perform action on Enter key press
txtUserid.clearFocus();
txtUserPasword.requestFocus();
return true;
}
return false;
}
});
txtUserPasword.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER))
{
// Perform action on Enter key press
// check for username - password correctness here
return true;
}
return false;
}
});
Another best solution would be:
android:singleLine="true"
android:imeOptions="actionNext"
If your EditText is supposed to have only 1 line, add the attribute android:singleLine="true" on your XML, that will remove the Enter key and replace it with Next / Done button.
add your xml layout ,
in suppose u want 4 edittext in row so first three editext u set below,
android:imeOptions="actionNext"
and last one editext u set
android:imeOptions="actionDone"
u add line so add,Use
android:singleLine="true"
You need to take care of few things:
Add android:singleLine="true".
Add android:nextFocusDown="#+id/tv2" on your XML.
Don't add android:imeOptions="actionNext", otherwise it will override above two attributes.
use this attribute:
android:inputType="textPersonName"
Add
android:inputType="text"
line in your edittext tag. and your problem will be resolved.
Just add android:singleLine="true" to the EditText tag in the layout XML..
Just add android:singleLine="true" you don't need that code for that
android:singleLine="true" is deprecated
use
android:maxLines="1"
android:inputType="text"
instead

Android disable Enter key in soft keyboard

Can anyone tell me how to disable and enable the Enter key in the soft keyboard?
just go to your xml and put this attribute in EditText
android:singleLine="true"
and your enter key will be gone
Attach OnEditorActionListener to your text field and return true from its onEditorAction method, when actionId is equal to IME_ACTION_DONE. This will prevent soft keyboard from hiding:
EditText txtEdit = (EditText) findViewById(R.id.txtEdit);
txtEdit.setOnEditorActionListener(new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
// your additional processing...
return true;
} else {
return false;
}
}
});
Refer this LINK.
Try this, together imeOptions = actionDone
<EditText
android:id="#+id/edittext_done"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone"
android:maxLines="1"/>
In the EditText's layout put something like this:
android:digits="abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ,"
You can also enumerate the rest of the symbols that you would like to be able to enter there, but not the enter key.
I know this question is quite old but an easy way of disabling the enter key is to set android:maxLines="1" in your EditText.

getting numeric keyboard default

How can I change android's default keyboard?
I want numeric keyboard to be shown first and then on clicking ABC in the numeric keyboard, I want to show alphabets keyboard.
Is that possible to implement?
Thanks in advance.
Assuming you're using a TextView for your text input, you simply need to set the inputMethod property.
http://developer.android.com/reference/android/widget/TextView.html#attr_android:inputMethod
As I said in this question, I didn't find any answer to that except if you wrote your own keyboard
You can do that with the word "phone" in inputype property of your EDITTEXT
Use InputType="number" in your edittext
Just implement IME option on your numeric keyboard and once clicked change input type programmatically like this:
EditText editText= (EditText) mView.findViewById(R.id.et_awesome);
editText.setOnEditorActionListener(new EditText.OnEditorActionListener() {
#Override
public boolean onEditorAction(EditText v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_GO) {
editText.setInputType(InputType.TYPE_CLASS_TEXT);
return true;
}
return false;
}
});
EditText on XML:
<EditText
...
android:imeOptions="actionGo"
android:imeActionLabel="ABC"
android:imeActionId="666"
android:inputType="number"/>

Categories

Resources