I am using phonegap plugin for my app written for android. The design was completely done using html. I want to handle the next key event in android soft keyboard during text field navigation because i have used some plugins like niceditor(which provides formatting options in text area). So when i click on next button in soft keyboard from the field before to niceditor it is not moving focus to the niceditor instead app gets collapsed sometimes it closes as device does not recognize the niceditor as text field and so it is not focused on clicking next. so i want it to be handled manually.
Thanks in advance if anybody can help me out to get the solution.
editText = (EditText)layout.findViewById(R.id.editText);
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
return false;
}
});
Related
I want to build a instant searchview, which will show the search result immediately in the same layout as soon as a user input anything. So I am googling and decide to use onQueryTextChange to implement that. However I cannot figure out how to "fire" a intent like the normal result which pressing ENTER will lead to, to tell my Activity that there is an event that a user have input something in searchview and you(Activity) should handle it.
Any idea to help?
If I understood you correcty you want to recognize KEY_EVENT (ENTER). I've ended with custom EditText styled like original SearchView, then used OnEditorActionListener:
queryEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH ||
(event != null && event.getKeyCode()==KeyEvent.KEYCODE_ENTER)) {
performSearch();
return true;
}
return false;
}
});
SearchView don't have setOnEditorActionListener method, thats why I'm using simple EditText
note EditorInfo.IME_ACTION_SEARCH option inside "if", you may request "special" keyboard layout with magnify icon instead of Enter key (but remember that not all keyboards are supporting this option and custom keyboard app may show "usual" layout of keyboard)
android:inputType="text|textNoSuggestions"
android:imeOptions="actionSearch"
I'm developing a mobile web application that contains a form with a textarea. Android, with the textarea on focus displays a Return button instead of Go button.
Is it possible to force the android soft keyboard to display a Go button instead of Return?
NOTE: it's a web application hence HTML not java
Please add following two lines to your edittext:
<EditText
android:singleLine="true"
android:imeOptions="actionGo"/>
This will enable Go button on your softkeyboard
And to listen Go button Add
editText.setOnEditorActionListener(){
#override
public boolean onEditorAction (TextView v, int actionId, KeyEvent event) {
if(actionId=EditorInfo.IME_ACTION_GO){
//perfrom your action
}
return false;
}
}
I have a form I'm trying to use on my Android phone which uses <input type="number">, but it does not submit when you press enter, it only moves to the next input box.
Is there any way to make the enter key on an Android submit the form instead?
Implement setOnEditorActionListener to manage this.
To summarise, you first need to add the following XML attribute to your EditText widget:
android:imeOptions="actionDone"
And somewhere in your activity, perhaps in the onCreate() method, add this:
EditText edittext= (EditText) findViewById(R.id.MY_EDITTEXT);
edittext.setOnEditorActionListener(new EditText.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
// Add the code for submitting here
return true;
}
return false;
}
});
You can also take a look at this thread for more details.
In default android webview always will focus next input element on press enter button. Also, don't use jquery focus out option in android and it will make problem some other android devices.
I've create a dialog with a multiline edittext-field. The problem is that the [ENTER]-key of the soft keyboard is closing the keyboard instead of creating a new line. With imeOptions, it's possible to configure a lot, but not a newline-command... How can I accomplish this?
Building for a Galaxy Tab 2 with Android 4.0.3.
I found out that setting the raw inputtype of the EditText to multiline is working where the "normal" input type isn't.
final EditText remark = new EditText(MyClass.this);
remark.setRawInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);
This did it for me.
You might be able to accomplish this by creating a new TextWatcher. Register this textwatcher to your EditText and implement a breakline when receiveing the return key.
EDIT:
To handle an individual key press, implement onKeyDown() or onKeyUp() as appropriate. Usually, you should use onKeyUp() if you want to be sure that you receive only one event. If the user presses and holds the button, then onKeyDown() is called multiple times.
For example:
#Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_ENTER:
/* This is a sample for handling the Enter button */
return true
default:
return super.onKeyUp(keyCode, event);
}
}
Source:
Android :
http://developer.android.com/training/keyboard-input/commands.html
A list of the KeyEvents:
http://developer.android.com/reference/android/view/KeyEvent.html
I have 6 Edittexts grouped in 6 differents layouts, all in the same view.
My problem is that my app is forced to landscape mode, and by pressing the 'next' button i want to automatically start to edit another editText rather than the one android set me by default. Example: i'm writing on EditText1, press next, and focus is taken by the EditText that is UNDER the 1st one. I want to edit the one that is RIGHT to it.
Sorry for my bad english :(
The device is a galaxy tab, with Google API8/Android 2.2
Thanks
Haven't tested it, but this should work
some_edittext.setOnEditorActionListener(new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_NEXT) {
some_button.performClick();
return true;
}
return false;
}
});
I might be wrong but I don't think there is any implicit way of doing it. You would need to write your own EditorAction.
You need to monitor everything that the user enters and whenever he presses 'NEXT', you would have to manually shift the focus to the next EditText, using EditorInfo.IME_ACTION_NEXT.