如何删除焦点没有设置焦点移到另一个控制? [英] How to remove focus without setting focus to another control?

查看:410
本文介绍了如何删除焦点没有设置焦点移到另一个控制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢我的用户界面直观易用,每个屏幕应该自然,悄悄地引导到应用程序中的下一个步骤的用户。除了上述,我努力使事情混乱,混杂的可能。

I like my UIs to be intuitive; each screen should naturally and unobtrusively guide the user on to the next step in the app. Barring that, I strive to make things as confusing and confounding as possible.

只是在开玩笑: - )

Just kidding :-)

我有三TableRows,每个都包含一个只读和不可聚焦的EditText控件,然后一个按钮,它的权利。每个按钮启动相同的活动,但有不同的观点。的用户进行选择那里和子活动完成后,填充合适的EditText与用户的选择。

I've got three TableRows, each containing a read-only and non-focusable EditText control and then a button to its right. Each button starts the same activity but with a different argument. The user makes a selection there and the sub-activity finishes, populating the appropriate EditText with the user's selection.

这是典型的级联值机制;每个选择缩小选择下可用的选项,等等。因此我在每个下一行禁用这两个控件,直至当前行上的EditText包含一个值。

It's the classic cascading values mechanism; each selection narrows the available options for the next selection, etc. Thus I'm disabling both controls on each of the next rows until the EditText on the current row contains a value.

我需要做两件事情之一,在preference顺序如下:

I need to do one of two things, in this order of preference:

  1. 点击一个按钮,立即删除重点不设置焦点到一个不同的按钮
  2. 设置焦点的第一个按钮,当活动开始

的子活动返回后,问题出现;被点击的按钮保留焦点。

The problem manifests after the sub-activity returns; the button that was clicked retains focus.

回复:上述#1 - 似乎没有成为一个removeFocus()方法,或类似的东西

Re: #1 above - There doesn't appear to be a removeFocus() method, or something similar

回复:#2上面 - 我可以使用不是requestFocus()将焦点设置到下一行上的按钮,与子活动返回后的工作,但由于某些原因,它不会在父活动的onCreate工作()

Re: #2 above - I can use requestFocus() to set focus to the button on the next row, and that works after the sub-activity returns, but for some reason it doesn't work in the parent activity's onCreate().

我需要在两个方向上的用户界面的一致性 - 无论是没有按钮的子活动结束后有焦点或每个按钮接收焦点取决于它的位置在逻辑流程,包括之前的任何的第一(也是唯一一个)主动按钮选择。

I need UI consistency in either direction--either no buttons have focus after the sub-activity finishes or each button receives focus depending on its place in the logic flow, including the very first (and only) active button prior to any selection.

谢谢, 杰夫

推荐答案

编辑为我找到了一个更好的解决方案:我有今天一个EditText删除焦点类似的问题,并找到<一href="http://stackoverflow.com/questions/6117967/how-to-remove-focus-without-setting-focus-to-another-control/6118033#6118033">this问题这可能会帮助你太(即使它好像你去了另一条路线) -

Edited as I found a better solution: I was having similar problems removing focus from an EditText today, and found this question which might help you too (even though it seems like you went down another route) -

使用clearFocus()似乎没有奏效,你发现了,但最终被添加为我工作:

Using clearFocus() didn't seem to be working as you found, but what worked for me in the end was adding:

<LinearLayout 
    android:id="@+id/my_layout" 
    android:focusable="true" 
    android:focusableInTouchMode="true" ...>

我的最顶层布局视图(线性布局)。从所有按钮/ EditTexts移除焦点等,则只能做

to my very top level Layout View (a linear layout). To remove focus from all Buttons/EditTexts etc, you can then just do

LinearLayout myLayout = (LinearLayout) activity.findViewById(R.id.my_layout);
myLayout.requestFocus();

请求焦点什么也没做,除非我设置视图要成为焦点。

Requesting focus did nothing unless I set the view to be focusable.

这篇关于如何删除焦点没有设置焦点移到另一个控制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆