Android OnEditorActionListener() actionId give 0 when I click Done
I have created a keyboard. When the user enters numbers they're sent to a particular EditText
, but when the user clicks on the "Done" key it doesn't go to setOnEditorActionListener
(but it does close the keyboard).
This is my code:
final EditText txtQty = new EditText(this);
txtQty.setHeight(1);
txtQty.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, 42));
txtQty.setInputType(InputType.TYPE_CLASS_PHONE);
txtQty.setImeOptions(EditorInfo.IME_ACTION_DONE);
txtQty.setSelectAllOnFocus(true);
txtQty.setTextSize(9);
txtQty.setVisibility(View.VISIBLE);
txtQty.setHint("0.0");
txtQty.setHighlightColor(R.color.green);
tr.addView(txtQty);
txtQty.setOnEditorActionListener( new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
Log.i("KeyBoard" ,"Inside the Edit Text");
if (actionId == EditorInfo.IME_ACTION_DONE ||actionId == EditorInfo.IME_ACTION_NEXT ) { ......}
Here it gives actionId = 0
and EditorInfo.IME_ACTION_NEXT = 5
When I run through the Android soft keyboard its working fine.
txtQty.setOnEditorActionListener( new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
Log.i("KeyBo开发者_如何转开发ard" ,"Inside the Edit Text");
Log.i("---EditorInfo.IME_ACTION_NEXT---" , EditorInfo.IME_ACTION_NEXT);
Log.i("---actionId---" , actionId);
Log.i("---event---" , event);
Log.i("---EditorInfo.IME_ACTION_DONE---" , EditorInfo.IME_ACTION_DONE);
Here it's giving EditorInfo.IME_ACTION_NEXT = 5, actionId = 5
and EditorInfo.IME_ACTION_DONE = 6, actionId = 6
But when I run through my soft keyboard it gives EditorInfo.IME_ACTION_NEXT = 5,
actionId = 0
and EditorInfo.IME_ACTION_DONE = 6, actionId = 0
.
Why didn't it take the actionId
value on my soft keyboard?
if you wanna got the actionid try this way:
in my project i change the edittext's properties like that
input type ----- text
ime options ----- actionDone
and in java file:
etSearch = (EditText) findViewById(R.id.etSearch);
etSearch.setOnEditorActionListener(mEditorActionListener);
private OnEditorActionListener mEditorActionListener = new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
// TODO Auto-generated method stub
if (actionId == EditorInfo.IME_ACTION_DONE) {
//do something
}
return false;
}
};
in this way could got the actionid = 6;
精彩评论