本文介绍了EditText's机器人:nextFocusDown attibute停止工作时的onClick设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道这是为什么了android:nextFocusDown attibute停止,当我们设置的onClick上它的工作

Does anybody knows why the android:nextFocusDown attibute stops working when we set the onClick on it?

在下面的例子中,我们有定义这个属性一些的EditText:

On the example below, we have some EditText with this attribute defined:

    <TableRow android:weightSum="1" android:gravity="center">
        <EditText android:id="@+id/txtChave1" android:maxLength="4"
            android:gravity="center" android:textSize="16dp"
            android:layout_height="wrap_content" android:layout_weight=".23"
            android:layout_width="0dp" android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp" android:singleLine="true"
            android:selectAllOnFocus="true" android:inputType="textCapCharacters"
            android:nextFocusDown="@+id/txtChave2">
        </EditText>
        <EditText android:id="@+id/txtChave2" android:maxLength="4"
            android:gravity="center" android:textSize="16dp"
            android:layout_height="wrap_content" android:layout_weight=".23"
            android:layout_width="0dp" android:layout_marginRight="5dp"
            android:singleLine="true" android:selectAllOnFocus="true"
            android:inputType="textCapCharacters" android:nextFocusDown="@+id/txtChave3">
        </EditText>
        <EditText android:id="@+id/txtChave3" android:maxLength="4"
            android:gravity="center" android:textSize="16dp"
            android:layout_height="wrap_content" android:layout_weight=".23"
            android:layout_width="0dp" android:layout_marginRight="5dp"
            android:singleLine="true" android:selectAllOnFocus="true"
            android:inputType="textCapCharacters" android:nextFocusDown="@+id/txtChave4">
        </EditText>
        <EditText android:id="@+id/txtChave4" android:maxLength="4"
            android:gravity="center" android:textSize="16dp"
            android:layout_height="wrap_content" android:layout_weight=".23"
            android:layout_width="0dp" android:layout_marginRight="5dp"
            android:singleLine="true" android:selectAllOnFocus="true"
            android:inputType="textCapCharacters">
        </EditText>
    </TableRow>

如上定义,当用户点击虚拟键盘上的下一个按钮,重点变化预期......但是,如果我们将onclick属性,在安卓nextFocusDown doen'科技工作了。

As defined above, when user clicks on the "next button" on virtual keyboard, the focus changes as expected... But, if we set the onClick attribute, the android:nextFocusDown doen´t work anymore.

        <EditText android:id="@+id/txtChave1" android:maxLength="4"
            android:gravity="center" android:textSize="16dp"
            android:layout_height="wrap_content" android:layout_weight=".23"
            android:layout_width="0dp" android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp" android:singleLine="true"
            android:selectAllOnFocus="true" android:inputType="textCapCharacters"
            android:nextFocusDown="@+id/txtChave2" android:onClick="onClickHandler">
        </EditText>

任何意见?

非常感谢!

推荐答案

编程这样做,因为当你打电话的android:nextFocusDown在XML可能是要在的nextfocus调用不会到创建它的对象。

Do it programmatically because when you call android:nextFocusDown in XML may be the object that you want to call in the nextFocus will not create it till.

private void setUpView(){
    editText1=(EditText)findViewById(R.id.editText1);
    editText2=(EditText)findViewById(R.id.editText2);
    editText3=(EditText)findViewById(R.id.editText3);
 }
private void setUpFocus(){
  editText1.setNextFocusDownId(R.id.editText2);
    editText2.setNextFocusDownId(R.id.editText8);// you can give focus to any id
    editText3.setNextFocusDownId(R.id.editText9);
 }

呼叫setupView函数()setUpFocus()之前在的onCreate()。

Call setUpView() before setUpFocus() in onCreate().

这篇关于EditText's机器人:nextFocusDown attibute停止工作时的onClick设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 20:14