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

发布于 2024-11-10 07:43:13 字数 143 浏览 0 评论 0原文

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

I have an activity with two EditTexts. If, in landscape mode, I select the first EditText, the keyboard that is displayed has a "next" button which should allow me to type in the second EditText. Likewise, the second EditText has a "done" button, which I would like to handle for completing the activity. How can I handle the selection of these buttons?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

宫墨修音 2024-11-17 07:43:13

关于如何解决此问题的文档相当少。我在此处找到了一个很好的解决方案。基本上,您可以为每个 EditText 添加 IME 选项:
对于第一个:

      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;
}
  });

There is fairly little documentation on how to solve this issue. I found a good solution here. Basically, you can add an IMEoption for each of the EditTexts:
For the first one:

      android:imeOptions="actionNext"

For the second one:

      android:imeOptions="actionDone"

To handle these in the code, try something like this:

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;
}
  });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文