我已经有了代码并且它在模拟器中工作但是当我尝试在我的设备上安装它时它没有工作?我的机器人是 Jellybean 4.1
edtNamaDokterPerasat.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// If the event is a key-down event on the "enter" button
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER)) {
namaDokter = edtNamaDokterPerasat.getText().toString();
Intent set = new Intent(getApplicationContext(),DaftarDokter.class);
// sending pid to next activity
set.putExtra(TAG_NAMA_DOKTER, namaDokter);
startActivityForResult(set, 0);
return true;
}
return false;
}
});
如何让它在设备上运行?如果我尝试按设备输入,结果将为ENTER' / n',如下面的下一行
答案 0 :(得分:0)
我在google nexus设备上尝试了以下代码。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EditText edittext = (EditText)findViewById(R.id.edittext);
edittext.setOnKeyListener(new EditText.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER)) {
finish();
Intent myIntent = new Intent(CurrentActivity.this, NextActivity.class);
myIntent.putExtra("key", "Enter"); //Optional parameters
CurrentActivity.this.startActivity(myIntent);
return true;
}
return false;
}
});
}