Can someone help me with a softkeyboard enter key listener?
I need a enter key listener like a button listener that would have a few editext listeners inside like this
enterkey.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(editext1.getText().toString().equalsIgnoreCase("test1")) {
button3.performClick();
}
if(editext1.getText().toString().equalsIgnoreCase("test2")) {
button4.performClick();
}
}
);
I also need to know if something like this is correct?
if(editext1.getText().toString().equals.null)) {
testwrong.setText("Wrong");
I have now tried using this code but keep getting a null value when I hit enter? Can anyone suggest a solution to avoid this?
editext.setOnKeyListener(new View.OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if (keyCode == KeyEvent.KEYCODE_ENTER) {
if ("test1".equalsIgnoreCase(anstext.getText().toString())) {
but4.performClick();
}
} else if ("test2".equalsIgnoreCase(editext.getText().toString())) {
but5.performClick();
}
if ("test5".equalsIgnoreCase(editext.getText().toString())) {
but6.performClick();
}
if ("test7".equalsIgnoreCase(editext.getText().toString())) {
but7.performClick();
}
if (editext.getText().toString() != null) {
testwrong.seText("wrong");
}
return true;
}
});
myTextView. setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { boolean handled = false; if (event. getAction() == KeyEvent. KEYCODE_ENTER) { // Handle pressing "Enter" key here handled = true; } return handled; } });
Android Event Listeners This method is called when the user touches or focuses on the item using navigation-keys or trackball or presses on the "enter" key or presses down on the trackball.
Assuming your keyboard is anything like mine: Try tapping the key bottom left till you get the ? 123 setting, then tap the upward-arrow key above it. Your emoticon key bottom right should then change to Enter.
In your EditText
you should specify keyboard action using imeOptions.
<EditText
android:id="@+id/query"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:imeOptions="actionGo"
android:inputType="text" />
And in your Activity's class:
EditText editText = (EditText) findViewById(R.id.query);
editText.setOnEditorActionListener(new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId,
KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_GO) {
return true;
}
return false;
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With