android:digits not allowing next button in keypad - android

Im using
android:digits="abcdefghijklmnopqrstuvwxyz. "
and having one more EditText in the same screen when i press enter key in keypad the focus doesn't gets changed.
suppose if i remove the
android:digits
the enter button works fine and moves to the next edit text.

Add android:imeOptions="actionNext" in your EditText in xml
<EditText
android:id="#+id/et_count"
android:layout_width="100dp"
android:singleLine="true"
android:imeOptions="actionNext"
android:layout_height="wrap_content" />

You can make use of the imeOptions attribute available for EditText in xml.
Try the following. It worked in my case.
In XML:
<EditText
android:id="#+id/edit_text1"
android:layout_width="match_parent"
android:layout_height="45dp"
android:digits="abcdefghijklmnopqrstuvwxyz. "
android:imeOptions="actionNext"/>
<EditText
android:id="#+id/edit_text2"
android:layout_width="match_parent"
android:layout_height="45dp"/>
Then, in JAVA:
EditText edit_text1 = (EditText) findViewById (R.id.edit_text1);
EditText edit_text2 = (EditText) findViewById (R.id.edit_text2);
edit_text1.setOnEditorActionListener(new OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = false;
if (actionId == EditorInfo.IME_ACTION_NEXT) {
edit_text2.requestFocus();
handled = true;
}
return handled;
}
});

you must be delete 'android:digits' to active the 'android:imeOptions="actionNext"' code.

Related

setOnEditorActionListener not working for edit texts next to each other end of layout

here' the code
I have two edit Text in a row in my lay out,and when I touch next on keyboard it does not change the focus.
the setOnEditorActionListener does not work till i add extra editText
<EditText
android:id="#+id/firstText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:imeOptions="actionNext"
android:inputType="numberDecimal"
/>
<EditText
android:id="#+id/secondText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:imeOptions="actionDone"
android:inputType="numberDecimal"
/>
code:
firstText.setOnNextActionListener(new CallBack<KeyEvent>() {
#Override
public void call(KeyEvent data) {
secondText.requestEditTextFocus();
}
});
Give one value into edittext in xml file ..
android:singleLine="true"
You can try these
android:nextFocusDown="#+id/secondText"
android:nextFocusLeft="#+id/secondText"
android:nextFocusRight="#+id/secondText"
android:nextFocusUp="#+id/secondText"
Show below three ways, you can got you want Using any one of them
inputType ="actionNext" attribute
or
android:imeOptions="actionNext"
or
android:singleLine="true" and
android:nextFocusDown="#+id/secondText"
on your .xml you can do this.
If you want to do it programmatically in your activity or fragment then try below:-
firstText.setOnEditorActionListener(new OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event){
if (actionId == EditorInfo.IME_ACTION_NEXT) {
secondText.requestEditTextFocus();
return true; // Focus will do whatever you put in the logic.
}
return false; // Focus will change according to the actionId
}
});
I have tested with set Programmtically with changes secondText.requestEditTextFocus(); to secondText.requestFocus(); and its working fine.
Please show below Screenshotes

How to pass control from one textview to other after pressing the enter button in keyboard?

I have two textViews shown below after pressing enter button in first textview the cursor should goes to second textview. How?
<AutoCompleteTextView
android:id="#+id/txt_login_username"
android:layout_width="300dp"
android:layout_height="40dp"
android:layout_above="#+id/pengala_logo"
android:layout_alignLeft="#+id/txt_login_pwd"
android:ems="10"
android:hint="Please enter Email"
android:inputType="textAutoComplete"
android:textColorHint="#ffffff"
android:textSize="20sp" />
<requestFocus />
<EditText
android:id="#+id/txt_login_pwd"
android:layout_width="300dp"
android:layout_height="40dp"
android:layout_alignLeft="#+id/btn_login_submit"
android:layout_alignTop="#+id/text"
android:ems="10"
android:hint="Please enter Password"
android:inputType="textPassword"
android:textColorHint="#ffffff"
android:textSize="20sp" />
try this, EditBox have the requestFocus() you can use this while clicking Button.
EditText.requestFocus();
I think it should work
EditText editText1=(EditText)findViewById(R.id.text1);
EditText editTtext2=(EditText)findViewById(R.id.text2);
editText1.setOnKeyListener(new OnKeyListener() {
#Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if(event.getKeyCode() == KeyEvent.KEYCODE_ENTER){
editTtext2.requestFocus();
}
return true;
}
});
Make editText1 single line true.
Looking at this question, you can simply use the
android:imeOptions="actionNext" option on your txt_login_username to change the 'enter' key to go to the 'next' input. You may need to specify android:singleLine="true", as this will not work on a multi-line input.
Documentation can be found here.
final EditText editText = (EditText) findViewById(R.id.editText1);
editText.setOnKeyListener(new OnKeyListener() {
#Override
public boolean onKey(View v , int keyCode , KeyEvent event) {
EditText editText2 = (EditText) findViewById(R.id.editText2);
// TODO Auto-generated method stub
if (keyCode == event.KEYCODE_A) {
Selection.setSelection((Editable) editText2.getText(),editText.getSelectionStart());
editText2.requestFocus();
}
return true;
}
});

Next edittext when enter clicked

I am trying to implement a button that does not move to next edittext when clicked. So here is my code:
<EditText
android:id="#+id/address_edittext"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:hint="#string/address_textview_hint"
android:imeActionLabel="#string/search_button"
android:imeOptions="actionNone"
android:inputType="textCapWords"
android:singleLine="true" />
When I click this button some actions are done by code, but incorrectly jumps to other edittext.
How could I fix that?
Use TextView.OnEditorActionListener here is LINK
see this example
editText = (EditText) findViewById(R.id.emai_text);
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_NEXT) {
// your action...........
}
return false;
}
});
just you need to add textMultiLine in addition to textCapWords
<EditText
android:id="#+id/editText_itemDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine|textCapWords"
/>

Set carat/cursor from edittext1 to edittext2

I've already searched how to do this but couldn't find any solution. Here it goes, I have edittext1 and edittext2, while the carat/cursor is positioned in edittext1 then I pressed "Next/Enter" key in soft keyboard, the carat/cursor must be positioned in edittext2. The snippet below received the event when I pressed the "Next/Enter" key but didn't move the carat/cursor in edittext2.
edittext1.setOnKeyListener(new View.OnKeyListener()
{
#Override
public boolean onKey(View v, int keyCode, KeyEvent event)
{
if(event.getKeyCode() == KeyEvent.KEYCODE_ENTER)
{
Editable e = edittext2.getText();
Selection.setSelection(e,e.length());
}
return false;
}
});
Any inputs will be highly appreciated. Thanks.
Rather than doing it in code, can't you use the android:nextFocusDown and android:nextFocusUp in your XML? Here are some references:
Handling UI Events
View documentation
EDIT
With your accepted answer it looks like you have a solution that works, however I thought I'd get the XML route to work too. So here is a working version of your layout elements:
<AutoCompleteTextView
android:id="#+id/autoCompleteTextViewRecipient"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:completionThreshold="1"
android:inputType="text"
android:maxLines="1"
android:hint="To"
android:imeOptions="actionNext"
android:nextFocusDown="#+id/editTextComposeMessage"
android:nextFocusUp="#+id/editTextComposeMessage"/>
<EditText
android:id="#+id/editTextComposeMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:nextFocusDown="#+id/autoCompleteTextViewRecipient"
android:nextFocusUp="#+id/autoCompleteTextViewRecipient"/>
Differences are that the AutoCompleteTextView now has a nextFocusDown, the EditText has a nextFocusUp, and both have imeOptions set to actionNext
Try using this:
if(event.getKeyCode() == KeyEvent.KEYCODE_ENTER)
{
edittext2.requestFocus();
}
The cursor moves to edittext2.

KeyCode_Enter to next edittext

In edittext, after typing 'Enter' key, system make a new line inside it. I'd like to focus on next edittext, no new line. how to code? my code in xml is below
<EditText
android:id="#+id/txtNPCode"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_alignLeft="#+id/lblNPCode"
android:layout_below="#+id/lblNPCode"
android:layout_centerHorizontal="true"/>
<EditText
android:id="#+id/txtCNPCode"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_alignLeft="#+id/lblCNPCode"
android:layout_below="#+id/lblCNPCode"
android:layout_centerHorizontal="true"/>
I also caputer key code in setOnKeyListener
tCNPCode.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if(keyCode == 66) {
Toast.makeText(S_PCode.this, "Enter Key", Toast.LENGTH_LONG).show();
//tNPCode.setFocusable(true);
}
return false;
}
});
You don't even have to use OnKeyListener. Simply add line android:singleLine="true" to your EditText. After this operation EditText behaves exactly like you want. So, in your particular case:
<EditText
android:id="#+id/txtNPCode"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_alignLeft="#+id/lblNPCode"
android:layout_below="#+id/lblNPCode"
android:layout_centerHorizontal="true"
android:singleLine="true"
/>
<EditText
android:id="#+id/txtCNPCode"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_alignLeft="#+id/lblCNPCode"
android:layout_below="#+id/lblCNPCode"
android:layout_centerHorizontal="true"
/>
solves the problem.
You have to use the requestFocus method. In your case it will be something like:
tCNPCode.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_ENTER) {
txtCNPCode.requestFocus();
}
return false;
}
});
The best way is to use one of the options for inputType, for example: android:inputType="textPersonName"
This will achieve the wanted effect. Check out the other options too, it'll save you some time in future :)
You shouldn't use android:singleLine="true", since it's deprecated. Here's what the documentations says about it:
This attribute is deprecated and is replaced by the textMultiLine
flag in the inputType attribute. Use caution when altering existing
layouts, as the default value of singeLine is false (multi-line
mode), but if you specify any value for inputType, the default is
single-line mode. (If both singleLine and inputType attributes are
found, the inputType flags will override the value of singleLine.).
Consider IME options, good description here http://androidcookbook.com/Recipe.seam;jsessionid=C824437B48F346E23FBE5828969029B4?recipeId=422 and documentation here http://developer.android.com/reference/android/widget/TextView.html#attr_android:imeOptions.
The only thing you need is add attribute android:imeOptions="actionNext" on each EditText. Keyboard appears with a Next key where Enter used to be and allows to navigate to the next EditText.
But order of "actionNext" is from top to bottom. For example, if you have horizontal layout:
<LinearLayout android:orientation="horizontal" >
<EditText android:id="#+id/et1" android:imeOptions="actionNext" />
<EditText android:id="#+id/et2" android:imeOptions="actionNext" />
</LinearLayout>
et2 never get focus. You should fix it in the code:
et1.setOnEditorActionListener(new OnEditorActionListener()
{
#Override
public boolean onEditorAction(TextView v, int actionId,
KeyEvent event)
{
switch (actionId)
{
case EditorInfo.IME_ACTION_NEXT:
boolean result = false;
TextView v1 = (TextView) v.focusSearch(View.FOCUS_RIGHT);
if (v1 != null)
result = v1.requestFocus(View.FOCUS_RIGHT);
else if (!result)
{
v1 = (TextView) v.focusSearch(View.FOCUS_DOWN);
if (v1 != null)
result = v1.requestFocus(View.FOCUS_DOWN);
}
if (!result)
v.onEditorAction(actionId);
break;
default:
v.onEditorAction(actionId);
break;
}
return true;
}
});
Original link: https://groups.google.com/forum/?fromgroups=#!topic/android-developers/OykOG6XtE8w
Use Single Line of Code (Java)
tCNPCode.setSingleLine(true);
Kotlin
tCNPCode.isSingleLine = true
It will navigate to the next item on Enter press
Just set the maximum number of line to the EditText box in xml layout file:
android:maxLength="1"

Categories

Resources