2013-03-04 43 views
6

我試圖趕上從屏幕上刪除鍵盤事件,我正在使用OnEditorActionListener類。但是,它的onEditorAction方法永遠不會被調用。Android。 onEditorAction從來沒有叫

這是我在XML的EditText:

<EditText 
    android:id="@+id/editTextSearch" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="20dp" 
    android:layout_marginLeft="10dp" 
    android:layout_marginRight="10dp" 
    android:layout_marginTop="50dp" 
    android:layout_weight="0.05" 
    android:background="@color/white" 
    android:ems="10"> 
</EditText> 

這是怎麼我與它的Java文件的工作:

private void createTextEdit() 
{ 
    EditText searchTextField = (EditText)findViewById(R.id.editTextSearch); 
    searchTextField.addTextChangedListener(new TextWatcher() 
    { 
     public void afterTextChanged(Editable s) 
     { 
      System.out.println("AFTER TEXT CHANGED");                
     } 
     public void beforeTextChanged(CharSequence s, 
     int start, int count, int after) 
     { 
      System.out.println("BEFORE TEXT CHANGED " + s); 
     } 

     public void onTextChanged(CharSequence s, 
       int start, int before, int count) 
     { 
      System.out.println(s); 
     } 
    }); 

    searchTextField.setOnEditorActionListener(new OnEditorActionListener() 
    { 
     public boolean onEditorAction(TextView v, int actionId, KeyEvent event) 
     { 

      System.out.println("ACTION ID " + actionId);//NEVER CALLED 

      if(actionId == EditorInfo.IME_ACTION_DONE) 
      { 
       System.out.println("ACTION DONE!!!!!!!!!!"); 
       return true; 
      } 

      return false; 
     } 
    }); 

    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
    imm.showSoftInput(searchTextField, InputMethodManager.SHOW_IMPLICIT); 
} 

不管我做什麼用searchTextField我是否開始編輯或完成它,所需的方法永遠不會被解僱。我究竟做錯了什麼?

回答

0

同在Nexus 7

這裏的問題,我認爲這是imeOptions,但沒有。

它可以在我的平板電腦上工作,如果我設置android:inputType="text"

我假設它可以與其他inputType一起使用。

我認爲這是Nexus上的一個錯誤。