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
Related
I have an EditText in my app with an input type of number:
<EditText
android:id="#+id/answerText"
style="#style/GeneralTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/question"
android:layout_toRightOf="#id/equals"
android:inputType="number"
android:paddingTop="#dimen/activity_vertical_margin"
android:maxLength="3"
android:visibility="invisible"
tools:text="ans"/>
So when the EditText has focus the numeric keyboard is displayed. I am trying to repond to the user pressing the tick button after supplying a value in the EditText but I can't get it to work.
I've tried the following code which I've put inside the onCreate method but it isn't working:
answerGivenText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE){
return true;
}
return false;
}
});
Can anyone help please?
I think you should add the
android:imeOptions="actionDone"
attribute to your edittext.
That code is exactly what you need, but you are not doing anything inside it, you're just intercepting the click and returning true, indicating that you handled it to other listeners on the stack.
You would do whatever it is you want to do when the user clicks the tick in the
if (actionId == EditorInfo.IME_ACTION_DONE)
section. And turn on the DONE action in your layout. What exactly are you trying to achieve?
I am trying to achieve exact inputType with no succes.
The criteria are following
DONE button is visible on the keyboard
when text is longer than 1 line, its wrapped to the next line
max height e.g 3 lines
Any idea how to get it?
if you want to use DONE Button you can't use multi lines just single line
<EditText
android:imeOptions="actionDone" // for adding DONE Button
android:inputType="textMultiLine" // for using multi lines , DONE Button will be disappeared. Use “text” instead.
android:maxLines="3" // 3 lines maximum
/>
To control DONE Button
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
if (i == EditorInfo.IME_ACTION_DONE){
// What do you want to do when clicking on Done Button
return true;
}
return false;
}
});
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.
In my login form when user clicks on an EditText and presses the enter key, this inserts a new line, therefore increasing the EditText's size. Next moment, it returns to its previous place and prints a dot in the password field (which is the next field).
I want to remove this enter key from the softkeyboard. Is it possible?
Use :
android:singleLine = "true"
or
edittext.setSingleLine();
And your ENTER key is gone
add this tag to textView in xml
android:singleLine = "true"
I am afraid you can't do this. But one thing is you can handle the softkeyboard keyevents like this,
edittext.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN
&& event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
Log.i("event", "captured");
return false;
}
else if(event.getAction() == KeyEvent.ACTION_DOWN
&& event.getKeyCode() == KeyEvent.KEYCODE_BACK){
Log.i("Back event Trigered","Back event");
}
}
}
return false;
}
});
Apart from this, you have to note that providing the attribute android:singleLine=true will make your edittext from growing in size when the soft keyborad ENTER is pressed
Inside the tag EditText you only have to do:
android:singleLine="true"
this remove the enter key in the keyboard
UPDATE
Inasmuch as android:singleLine="true" is deprecated I use android:maxLines="1" to avoid the enter in a EditText. How the name of the method says only N lines is permitted.
New update :
android:maxLines="1"
If you want something more generic in your .java:
boolean state = true;
yourTextInputEditText.setSingleLine(state);
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"