EditText上的全选()不选择文本,而不是光标移动到位置0 [英] EditText's selectAll() does not select the text, instead cursor is moved to position 0
问题描述
我的情况是:我有一个的EditText
,并在其下我有一个按钮,所谓的全选。它的目的是让用户选择全部由pressing它的文本。结果
当点击该按钮时,我调用全选()
在的EditText
不过的,而不是选择所有文字,在一些例(通常,当光标已经定位在文本内的某处),将光标移动到位置 0
(文开始)和文本仍然未选中。然后在第二个按钮,点击会选择所有。当然,它应该发生在第一次点击。搜索结果
从这个问题:<一href=\"http://stackoverflow.com/questions/11793635/android-edittext-selectall-doesnt-works-if-one-taps-on-the-same-field-in-andr\">Android EditText上全选()不工作,如果一个在Android中4.x的同一领域水龙头只有看来,这是在Android 4.0及以上的错误。 (发现在谷歌问题跟踪不提)。结果
有谁知道一个方法来解决这个问题?看来,万阿英,蒋达清也是其他选择方法,而不仅仅是全选()
搜索结果
(PS这个问题是那种重复我上面提到的问题,但我打开了另一个问题,因为这个问题的作者是满意,并选择了部分答案(设定的android:selectAllOnFocus =真
),而在我的情况和场景中它并不能帮助我,没有解决不了的问题。搜索结果
谢谢你。
My situation is: I have a EditText
, and under it I have a button, called "select all". It's purpose is to let the user select all the text by pressing it.
When the button is clicked, I invoke selectAll()
on the EditText
, but instead of selecting all text, in some cases (generally, when the cursor is already positioned within the text somewhere), the cursor is moved to position 0
(start of text) and text remains unselected. Second click on the button will then select all. But of course it should happen on first click.
From this issue: Android EditText selectAll() doesn't works if one taps on the same field in android 4.x only it seems that this is a bug in android 4.0 and above. (Found no mention in Google issue tracker).
Does anyone know about a way to overcome this problem? It seems that the probelm is also in other selection methods and not only selectAll()
.
(p.s. This question is sort of duplicate of the issue I mentioned above. But I opened another question, because the author of that issue was satisfied and selected a partial answer (of setting android:selectAllOnFocus="true"
), while in my case and scenario it does not help me and does not solve the problem.
Thanks.
推荐答案
我有一个类似的问题。我解决它(在C#中使用Xamarin,但相应的Java将工作)具有以下code:
I was having a similar issue. I solved it (using Xamarin in C#, but the equivalent Java will work) with the following code:
private void InitFocus()
{
Java.Lang.Runnable rable = new Java.Lang.Runnable(()=>
{
EditText maleCount = FindViewById<EditText>(Resource.Id.txtMaleCount);
maleCount.RequestFocus();
maleCount.SelectAll();
});
new Handler().Post(rable);
}
我有2个控制器:一个是下拉菜单,让您选择一个鸡笼,然后为一周的每一天一组按钮。无论何时更改一周中的一天或鸡舍,我想将焦点设置在 txtMaleCount
的EditText
然后我想在选择了框中的值(因为它是一个数字,他们是presumably要取代它)。
I have 2 controls: One is a dropdown that lets you select a chicken house and then a set of buttons for each day of the week. Whenever you change the day of week or the chicken house, I want to set focus in the txtMaleCount
EditText
and then I want the value in that box selected (since it's a number and they're presumably going to replace it).
显然,非直观的部分是需要发表
它。直接这样做(在UI线程)似乎没有任何效果。
Clearly, the non-intuitive part was the need to Post
it. Doing it directly (on the UI thread) didn't seem to have any effect.
这篇关于EditText上的全选()不选择文本,而不是光标移动到位置0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!