按Tab键时向下移动

时间:2011-12-04 08:41:36

标签: android android-2.2-froyo

我正在尝试将焦点移动到下一个字段/按钮,但它似乎不想工作。这是我现在拥有的:

    @Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (event.getKeyCode() == KeyEvent.KEYCODE_TAB) 
    {   
        //move down here once I figure it out..
        mEmailvalue.getNextFocusDownId();
        return true;

       }  
    return super.dispatchKeyEvent(event);
}

1 个答案:

答案 0 :(得分:2)

试试这个:

public boolean dispatchKeyEvent(KeyEvent event) {
    if (event.getKeyCode() == KeyEvent.KEYCODE_TAB && event.getAction()==KeyEvent.ACTION_DOWN) {
        View currentFocus = getCurrentFocus();
        if (currentFocus!=null) {
            View next = currentFocus.focusSearch(View.FOCUS_DOWN);
            if (next!=null) {
                next.requestFocus();
            }
        }
        return true;
    }  
    return super.dispatchKeyEvent(event);
}