我有一些适用于 EditText 字段的代码,但是当我更改焦点时会记录此错误(根据需要更改焦点):
InputEventConsistencyVerifier KeyEvent: ACTION_UP but key was not down
有人可以解释为什么吗?
我阅读了创建此错误的 InputEventConsistencyVerifier 源,但我不明白它是如何发生的。我尝试删除 list.requestFocus()。但如果没有那条线,焦点将停留在 EditText 字段上。但是,删除该行确实消除了日志中的错误。
public class AddDeleteActivity extends FragmentActivity {
private final String TAG = "AddDeleteName";
/*
* (non-Javadoc)
*
* @see android.app.Activity#onCreate(android.os.Bundle)
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
Log.e(TAG, "about to load fragment");
setContentView(R.layout.add_delete_child_layout);
Log.e(TAG, "finished loading fragment");
final EditText nameTextField = (EditText) findViewById(R.id.new_child);
nameTextField
.setOnEditorActionListener(new OnEditorActionListener() {
@Override
˚ public boolean onEditorAction(TextView v, int actionId,
KeyEvent event) {
Log.e(TAG, "onEditorAction: " + actionId);
String name = nameTextField.getText()
.toString();
Log.e(TAG, " name: " + name);
InputMethodManager inputManager = (InputMethodManager) v
.getContext().getSystemService(
Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(
v.getWindowToken(), 0);
Log.e(TAG, "change focus to List");
View list = findViewById(R.id.modchild_fragment);
/*** FOLLOWING LINE GENERATES ERROR *****/
list.requestFocus();
return false;
}
});
}
}
.xml:
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/modchild_fragment"
android:name="com.projectx.control.AddDeleteChild"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</fragment>
<EditText
android:id="@+id/new_child"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="enter launch codes"
android:imeOptions="actionDone"
android:inputType="text"
android:singleLine="true" />
谢谢!