0

I have 3 EditTexts in a row but on 3 different layouts. I set them up so when i click enter,it will jump to the next EditText from that row,on the next layout.The problem is that when i click enter from the first EditText on the row,it goes to the third.From the third it goes to the second and from the second to the first.It's like i press enter on the first EditText,it goes to the second and then to the third on the same enter. How can i stop it from jumping for example from the first EditText to the second and then the third on the same press of the enter key?

Here's some of my code :

et.setOnKeyListener(new OnKeyListener() {
    public boolean onKey(View v1, int keyCode, KeyEvent KEYCODE_ENTER) {
        l2.getChildAt(localizarer).requestFocus();
        return true;
    }
});

et2.setOnKeyListener(new OnKeyListener() {
    public boolean onKey(View v2, int keyCode, KeyEvent KEYCODE_ENTER) {
        l3.getChildAt(localizarer).requestFocus();
        return true;
    }
});

et3.setOnKeyListener(new OnKeyListener() {
    public boolean onKey(View v3, int keyCode, KeyEvent KEYCODE_ENTER) {
        l1.getChildAt(localizarer).requestFocus();
        return true;
    }
});

It's like i need some kind of break function,lol. How can i fix this ? Thanks and have a nice day/night !

Fixed by doing this :

et.setOnKeyListener(new OnKeyListener() {

    public boolean onKey(View v, int keyCode, KeyEvent event) {
        // If the event is a key-down event on the "enter" button
        if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
                    (keyCode == KeyEvent.KEYCODE_ENTER))
        {
            // Perform action on key press
            l2.getChildAt(localizarer).requestFocus();
            return true;
        }
        return false;
    }
});

But now an older issue is back,it jumps to my second row of edittexts instead of going to the first child in the layout it goes to the second..

4

2 回答 2

0

您的 xml 中定义的编辑文本是否以正确的顺序排列?如果这不起作用,您可以使用

android:nextFocusDown

设置顺序

于 2013-06-18T21:24:19.587 回答
0

你为什么不使用:

et1.requestFocus();

代替

l1.getChildAt(localizarer).requestFocus();
于 2013-06-18T21:28:07.200 回答