如何使用android横向键盘按钮?

时间:2011-05-27 20:36:31

标签: android keyboard android-edittext landscape

我有两个EditTexts的活动。如果在横向模式下,我选择第一个EditText,则显示的键盘有一个“下一步”按钮,允许我输入第二个EditText。同样,第二个EditText有一个“完成”按钮,我想为完成活动而处理。如何处理这些按钮的选择?

1 个答案:

答案 0 :(得分:3)

关于如何解决此问题的文档很少。我找到了一个很好的解决方案here。基本上,您可以为每个EditTexts添加IMEoption: 对于第一个:

      android:imeOptions="actionNext"

对于第二个:

      android:imeOptions="actionDone"

要在代码中处理这些,请尝试以下方法:

EditText departureAddress, destinationAddress;
departureAddress = (EditText)findViewById(R.id.departure);
//Set the action of the "next" button to bring destinationAddress to focus
destinationAddress(new OnEditorActionListener(){
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
  if (actionId == EditorInfo.IME_ACTION_NEXT) {
      destinationAddress.requestFocus();
  }
  return true;
}
  });
  destinationAddress = (EditText)findViewById(R.id.destination);
  //Set the action of the "done" button to handle the map query
  destinationAddress.setOnEditorActionListener(new OnEditorActionListener(){
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
  if (actionId == EditorInfo.IME_ACTION_DONE) {
      //Handle map query
  }
  return true;
}
  });