为什么我的 Android 应用程序上的 IME 与它应该编辑的 EditText 解除关联?

发布于 2024-10-09 01:05:39 字数 1216 浏览 5 评论 0原文

我正在编写一个 Android 应用程序。它有一个 ListActivity ,它全部设置为使用每个项目的此布局加载我的数据。

我的数据适配器绑定没有问题,并且我已经将其设置为当从列表中选择一个项目时调用此方法。

private void showPasswordBox(View v) {
 EditText passwordBox = (EditText)v.findViewById(R.id.hidden_box);
 Button passwordSubmit = (Button)v.findViewById(R.id.hidden_box_submit);

 passwordSubmit.setText("Login");
 passwordSubmit.setVisibility(View.VISIBLE);

 passwordBox.setFocusableInTouchMode(true);

 passwordBox.setHint(R.string.password);
 passwordBox.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
 passwordBox.setVisibility(View.VISIBLE);
}

这具有显示 EditText 和按钮(我的布局中的hidden_​​box 和hidden_​​box_submit)的效果。这正是我想要的。

然而,当用户点击新可见的 EditText (hidden_​​box) 时,就会出现问题。 IME 弹出,hidden_​​box 立即失去焦点。因此,在 IME 上键入的任何内容都不会出现在 EditText 中。相反,它正在做这种奇怪的事情,输入的任何内容都会以灰色字母显示在键盘上方,并且当 IME 关闭时保留在屏幕底部。这就像 IME 正在向它自己的临时隐形框中输入内容。

如果用户在 IME 显示后点击 EditText,则应用程序将按其应有的方式运行。在 IME 上键入的任何内容都会显示在 EditText 中,并在 IME 关闭时保留下来。

在我看来,当 IME 弹出时(当用户点击 EditText 时,它会立即执行,这是应该的),它完全与我的应用程序解除关联,并在 IME la-la land 中执行它的操作,除非我将其定向到通过在键入并关闭键盘之前点击 EditText 来编辑 EditText。我如何让它表现正常,以便它一弹出就直接输入到 EditText 中?

I've got an Android application I'm writing. It has a ListActivity in it that's all set up to load my data using this layout for each item.

My data Adapter binds with no problem and I've set it up so that when an item is selected from the list this method is called.

private void showPasswordBox(View v) {
 EditText passwordBox = (EditText)v.findViewById(R.id.hidden_box);
 Button passwordSubmit = (Button)v.findViewById(R.id.hidden_box_submit);

 passwordSubmit.setText("Login");
 passwordSubmit.setVisibility(View.VISIBLE);

 passwordBox.setFocusableInTouchMode(true);

 passwordBox.setHint(R.string.password);
 passwordBox.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
 passwordBox.setVisibility(View.VISIBLE);
}

This has the effect of displaying and EditText and a Button (hidden_box and hidden_box_submit in my layout). Which is just what I wanted.

However a problem occurs when the user taps on the newly visible EditText (hidden_box). The IME pops up and hidden_box immediately loses focus. Consequently anything typed on the IME does not appear in the EditText. Instead it's doing this weird thing where anything typed appears above the keyboard in grey letters and remains at the bottom of the screen when the IME is dismissed. It's like the IME is typing into it's own temporary invisible box.

If the user taps on the EditText after the IME is already showing then the application behaves as it should. Anything typed on the IME appears in the EditText and remains when the IME is dismissed.

It seems to me that when the IME pops up (which it does immediately when the user taps on the EditText, as it should) it completely de-associates with my application and does its thing in IME la-la land unless I direct it to the EditText by tapping on the EditText before typing and dismissing the keyboard. How do I make it behave normally so it types directly into the EditText as soon as it pops up?

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

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

发布评论

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

评论(1

请远离我 2024-10-16 01:05:39
       passwordBox.setFocusableInTouchMode(true);

希望这会起作用。是吗?

       passwordBox.setFocusableInTouchMode(true);

Hope this will work. Does it?

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