2011-10-05 5 views
1

キーボードを作成しました。ユーザーが数字を入力すると、特定のEditTextに送信されますが、ユーザーが「完了」キーをクリックすると、setOnEditorActionListenerにはなりません(キーボードは閉じます)。Android OnEditorActionListener()actionIdは、完了をクリックすると0を返します。

これは私のコードです:私はAndroidのソフトキーボードその作業罰金を介して実行すると

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) { ......} 

は、ここでは、actionId = 0EditorInfo.IME_ACTION_NEXT = 5

を与えます。ここで

txtQty.setOnEditorActionListener(new OnEditorActionListener() { 
     public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 
      Log.i("KeyBoard" ,"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); 

それはEditorInfo.IME_ACTION_NEXT = 5, actionId = 5

EditorInfo.IME_ACTION_DONE = 6, actionId = 6を与えている。しかし、私は私のソフトキーボードを介して実行する際には、EditorInfo.IME_ACTION_NEXT = 5, actionId = 0EditorInfo.IME_ACTION_DONE = 6, actionId = 0を与えます。

なぜ私のソフトキーボードでactionIdの値を取らなかったのですか?

答えて

3

あなたはたいたActionは、この方法を試してしまった場合:

私のプロジェクトで、私はその

input type ----- text 
ime options ----- actionDone 

とJavaファイルのようのEditTextのプロパティを変更します。

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; 
    } 
}; 

このようにactionid = 6が得られた。

関連する問題