【发布时间】:2015-03-10 16:29:54
【问题描述】:
我正在尝试处理键盘响应:
EditText editText = (EditText) findViewById(R.id.password);
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = false;
Log.d(TAG, "IME_ACTION_GO int:"+ IME_ACTION_GO+ " action id: "+ actionId);
if (actionId == IME_ACTION_GO) {
handled = true;
Toast toast = Toast.makeText(getApplicationContext(),"GO pressed", Toast.LENGTH_SHORT);
toast.show();
}
return handled;
}
});
我的布局 xml 是:
<EditText
android:id="@+id/password"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:hint= "Password"
android:inputType="textPassword"
android:layout_alignBottom="@+id/button"
android:layout_alignLeft="@+id/user_name"
android:layout_alignStart="@+id/user_name"
android:singleLine="true"
android:imeOptions="actionGo"
android:imeActionLabel="Login"/>
但是,actionID 始终为 0,而 IME_ACTION_GO 的 int 值为 2。因此 if 语句永远不会为真。
【问题讨论】:
-
Logcat 是否表明它们在您的 if 语句之前是相同的? Log.d(TAG, "IME_ACTION_GO int:"+ IME_ACTION_GO+ " action id: "+ actionId);
-
在 if 语句之前它们是不一样的。这些值并没有神奇地改变,但从一开始它们就分别是 2 和 0。
-
所以它为空,这可能会对您有所帮助stackoverflow.com/questions/11301061/…
标签: android