有没有人能帮我弄个软键盘enter键监听器?
我需要一个enter键监听器,比如一个按钮监听器,里面有几个editext监听器,像这样
enterkey.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(editext1.getText().toString().equalsIgnoreCase("test1")) {
button3.performClick();
}
if(editext1.getText().toString().equalsIgnoreCase("test2")) {
button4.performClick();
}
}
);我还需要知道这样的事情是否正确?
if(editext1.getText().toString().equals.null)) {
testwrong.setText("Wrong"); 我现在已经尝试使用此代码,但当我按回车键时,仍然得到一个空值。有没有人能提出一个解决方案来避免这种情况?
editext.setOnKeyListener(new View.OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if (keyCode == KeyEvent.KEYCODE_ENTER) {
if ("test1".equalsIgnoreCase(anstext.getText().toString())) {
but4.performClick();
}
} else if ("test2".equalsIgnoreCase(editext.getText().toString())) {
but5.performClick();
}
if ("test5".equalsIgnoreCase(editext.getText().toString())) {
but6.performClick();
}
if ("test7".equalsIgnoreCase(editext.getText().toString())) {
but7.performClick();
}
if (editext.getText().toString() != null) {
testwrong.seText("wrong");
}
return true;
}
});发布于 2012-10-17 23:29:51
发布于 2012-10-17 23:32:51
在EditText中,您应该使用imeOptions指定键盘操作。
<EditText
android:id="@+id/query"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:imeOptions="actionGo"
android:inputType="text" />在你的练习课上:
EditText editText = (EditText) findViewById(R.id.query);
editText.setOnEditorActionListener(new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId,
KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_GO) {
return true;
}
return false;
}
});https://stackoverflow.com/questions/12937731
复制相似问题