在 Android 模拟器上复制物理键盘

发布于 2024-10-18 00:56:17 字数 973 浏览 6 评论 0原文

我最近的应用程序收到了几份关于与带有物理键盘、EditText 和方向更改的手机相关的错误的报告。

我没有带物理键盘的手机,所以我必须尝试以某种方式重现该问题。在 Eclipse AVD 管理器下的模拟器创建屏幕中,有一个“键盘支持”选项。这是我在模拟器上复制物理键盘手机的方式吗?

还有其他方法可以调试我的问题吗?谢谢。

根据请求进行编辑:用户传达的当前症状是

  1. EditText 首选项未保存(我根据他们的输入做出此假设),
  2. 原因是用户打开时活动未正确切换方向向上键盘。它需要用户打开它两次。

完整的活动代码。注意:下面的 EditText 不是问题 EditText

public class GreetingOptions extends PreferenceActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.layout.greeting_options);

        //Set the edit text preference to only accept positive integers
        EditTextPreference fontSize = (EditTextPreference) findPreference("fontSize");
        EditText myEditText = (EditText) fontSize.getEditText();
        myEditText.setKeyListener(DigitsKeyListener.getInstance(false, false));

    }
}

I have a couple of reports on my recent app of a bug related to a phone with a physical keyboard, an EditText, and an orientation change.

I don’t have a phone with a physical keyboard, so I have to try to replicate the problem somehow. In the emulator creation screen under the AVD manager in Eclipse, there is an option for “keyboard support.” Is this how I would replicate a physical keyboard phone on the emulator?

Are there any other ways I could debug my problem? Thanks.

Edit upon request: Current symptoms as communicated by the user are

  1. EditText Preference not getting saved (I'm making this assumption based on their input)
  2. Something to due with the activity not switching orientation properly when the user opens up the keypad. It requires the user to open it twice.

Complete Activity code. NOTE: The EditText below is not the problem EditText.

public class GreetingOptions extends PreferenceActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.layout.greeting_options);

        //Set the edit text preference to only accept positive integers
        EditTextPreference fontSize = (EditTextPreference) findPreference("fontSize");
        EditText myEditText = (EditText) fontSize.getEditText();
        myEditText.setKeyListener(DigitsKeyListener.getInstance(false, false));

    }
}

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

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

发布评论

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

评论(2

∞觅青森が 2024-10-25 00:56:17

当用户滑出物理键盘时,您的应用程序将被销毁并重新创建,就像方向更改时发生的情况一样。我建议尝试使用方向改变来重现该问题。您可以使用以下命令在模拟器中完成此操作:

切换到以前的布局方向(例如,纵向、横向)KEYPAD_7、Ctrl-F11
切换到下一个布局方向(例如,纵向、横向)KEYPAD_9、Ctrl-F12

要解决此问题,我怀疑您需要在应用程序被破坏时保存 Activity 的状态,并在应用程序被破坏时恢复它它被重新创建。您可能会发现查看应用程序生命周期很有用。

When a user slides out a physical keyboard your app is destroyed and recreated, just the same as what happens when the orientation changes. I would suggest attempting to replicate the problem using an orientation change. You can accomplish this in the emulator using:

Switch to previous layout orientation (for example, portrait, landscape) KEYPAD_7, Ctrl-F11
Switch to next layout orientation (for example, portrait, landscape) KEYPAD_9, Ctrl-F12

To fix the issue I suspect you will need to save the state of your Activity when your app is destroyed and restore it when it is recreated. You may find it useful to review the application lifecycle.

忘羡 2024-10-25 00:56:17

这并不是真正的答案,但我对模拟器的经验是,它对任何“物理”输入的支持仅限于无。即使尝试模拟插入耳机也超出了它的处理能力。

我建议你尝试乞求、借用或偷取一部带键盘的真实手机,然后在上面安装该应用程序。

抱歉,我无法提供更多帮助:(

This isn't really an answer, but my experience with the emulator is that its support for any 'physical' inputs is limited to none. Even trying to simulate having a headset plugged in was more than it could handle.

I'd suggest you try to beg, borrow or steal a real phone with a keyboard, and install the app on that.

Sorry I can't be more help :(

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