在 Android 模拟器上复制物理键盘
我最近的应用程序收到了几份关于与带有物理键盘、EditText 和方向更改的手机相关的错误的报告。
我没有带物理键盘的手机,所以我必须尝试以某种方式重现该问题。在 Eclipse AVD 管理器下的模拟器创建屏幕中,有一个“键盘支持”选项。这是我在模拟器上复制物理键盘手机的方式吗?
还有其他方法可以调试我的问题吗?谢谢。
根据请求进行编辑:用户传达的当前症状是
- EditText 首选项未保存(我根据他们的输入做出此假设),
- 原因是用户打开时活动未正确切换方向向上键盘。它需要用户打开它两次。
完整的活动代码。注意:下面的 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
- EditText Preference not getting saved (I'm making this assumption based on their input)
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当用户滑出物理键盘时,您的应用程序将被销毁并重新创建,就像方向更改时发生的情况一样。我建议尝试使用方向改变来重现该问题。您可以使用以下命令在模拟器中完成此操作:
要解决此问题,我怀疑您需要在应用程序被破坏时保存
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:
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.这并不是真正的答案,但我对模拟器的经验是,它对任何“物理”输入的支持仅限于无。即使尝试模拟插入耳机也超出了它的处理能力。
我建议你尝试乞求、借用或偷取一部带键盘的真实手机,然后在上面安装该应用程序。
抱歉,我无法提供更多帮助:(
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 :(