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"
/>
Related
I would like to know how can I add an event/action for pressing the "Enter" button on the keyboard.
"The action would be the same as pressing the Button that I created on my application"
You can use imeOptions attribute to specify an action on your EditText
<EditText
android:id="#+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/password_hint"
android:inputType="textPassword"
android:imeOptions="actionLogin" />
and then create a listener on your activity/fragment for that action
EditText password = (EditText) findViewById(R.id.password);
password.setOnEditorActionListener(new OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_LOGIN) {
login();
}
return false;
}});
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.
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;
}
});
I set an Ok key on soft android keyboard when i click on the edittext shown below:
<EditText
android:id="#+id/rlMP3SeekContainer"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="1"
android:background="#drawable/text_rougea"
android:singleLine="true"
android:imeOptions="actionDone"
android:ems="10"
android:hint="#string/hint_deezer_search"
android:paddingLeft="#dimen/eight_dp"
android:paddingRight="#dimen/eight_dp"
android:textColor="#color/black"
android:textColorHint="#color/gray_text"
android:textSize="#dimen/twelve_sp" />
When the keyboard appear i want the user when clicking on the ok button do something. but how can i override the ok button on the keyboard to do whatever i want
You need to implement the OnEditorActionListener:
yourEditText.setOnEditorActionListener(
new EditText.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
/* your code here */
}
}
});
I'm trying to get this working: in my XML in EditText I have:
android:imeActionLabel="Search"
android:imeOptions="actionSearch"
But it doesn't work. In code
search.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
Doesn't work either. Any clues?
try this
in your xml file
<EditText
android:id="#+id/rechercheTextView"
android:layout_width="174dp"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:imeOptions="actionSearch"
android:inputType="text"
/>
in your Activity
EditText rechTxt = (EditText) findViewById(R.id.rechercheTextView);
rechTxt.setOnEditorActionListener(new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId,
KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
Toast.makeText(getApplicationContext(),"search",Toast.LENGTH_LONG).show();
return true;
}
return false;
}
});