这是我的代码:
uam.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View view, int keyCode, KeyEvent event){
if (event.getAction() == KeyEvent.ACTION_DOWN){
switch (keyCode)
{
case KeyEvent.KEYCODE_DPAD_CENTER:
case KeyEvent.KEYCODE_ENTER:
if(((EditText)findViewById(view.getId())) == ((EditText)findViewById(R.id.UamEditTextFm)))
{
Log.d("setOnKeyListener","Uam To port");
((EditText) findViewById(R.id.PortAdvFm)).requestFocus();
}
return true;
default:
break;
}
}
return false;
}
});
port.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View view, int keyCode, KeyEvent event){
if (event.getAction() == KeyEvent.ACTION_DOWN){
switch (keyCode)
{
case KeyEvent.KEYCODE_DPAD_CENTER:
case KeyEvent.KEYCODE_ENTER:
if(((EditText)findViewById(view.getId())) == ((EditText)findViewById(R.id.PortAdvFm)))
{
Log.d("setOnKeyListener","Port To ConType");
((EditText) findViewById(R.id.ConTypeAdvFm)).requestFocus();
}
return true;
default:
break;
}
}
return false;
}
});
connectType.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View view, int keyCode, KeyEvent event){
if (event.getAction() == KeyEvent.ACTION_DOWN){
switch (keyCode)
{
case KeyEvent.KEYCODE_DPAD_CENTER:
case KeyEvent.KEYCODE_ENTER:
if(((EditText)findViewById(view.getId())) == ((EditText)findViewById(R.id.ConTypeAdvFm)))
{
Log.d("setOnKeyListener","ConType To saveBtn ");
((Button) findViewById(R.id.SaveAdvSettingofFm)).requestFocus();
((Button) findViewById(R.id.SaveAdvSettingofFm)).performClick();
}
return true;
default:
break;
}
}
return false;
}
});
单击 Enter 时,它不关注port
,但焦点转到该connectType
字段。
请帮帮我。xml文件是:
<TableLayout android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TableRow android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="horizontal">
<TextView android:text="UAM:" />
<EditText android:id="@+id/UamEditTextFm" android:singleLine="true" android:inputType="textPersonName"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:autoText="true" />
</TableRow>
<TableRow android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="horizontal">
<TextView android:text="Port:" />
<EditText android:layout_height="wrap_content" android:singleLine="true" android:inputType="textPersonName"
android:layout_width="fill_parent"
android:id="@+id/PortAdvFm" />
</TableRow>
<TableRow android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="horizontal">
<TextView android:text="ConType:" />
<EditText android:layout_height="wrap_content" android:singleLine="true" android:inputType="textPersonName"
android:layout_width="fill_parent"
android:id="@+id/ConTypeAdvFm" />
</TableRow>
</TableLayout>
<Button android:id="@+id/SaveAdvSettingofFm" android:text="Save"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_gravity="right" android:layout_margin="5dp"/>