Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android EditText未接收选项卡键事件-库存软vk_Android_Listview_Tabs_Android Edittext_Keyevent - Fatal编程技术网

Android EditText未接收选项卡键事件-库存软vk

Android EditText未接收选项卡键事件-库存软vk,android,listview,tabs,android-edittext,keyevent,Android,Listview,Tabs,Android Edittext,Keyevent,我的应用程序下面有一个列表视图和一个编辑文本。由于某些原因,TAB键不会触发onKeyListener。我正在处理的所有其他键(DEL、ENTER、DPAD_UP/DOWN/CENTER)都接收到了。我在dispatchKeyEvent中添加了一个断点,再次没有收到TAB事件 我的应用程序以前有一个大的文本视图,用于显示文本,在此期间,选项卡事件接收良好。ListView现在已经取代了TextView 我完全搞不懂为什么不再收到TAB事件。这是一个库存Xoom,运行ICS4.0.4和库存N1,以

我的应用程序下面有一个
列表视图
和一个
编辑文本
。由于某些原因,TAB键不会触发onKeyListener。我正在处理的所有其他键(DEL、ENTER、DPAD_UP/DOWN/CENTER)都接收到了。我在
dispatchKeyEvent
中添加了一个断点,再次没有收到TAB事件

我的应用程序以前有一个大的
文本视图
,用于显示文本,在此期间,选项卡事件接收良好。
ListView
现在已经取代了
TextView

我完全搞不懂为什么不再收到TAB事件。这是一个库存Xoom,运行ICS4.0.4和库存N1,以及2.3.6

我使用
TextView
将当前代码与版本进行了比较,大部分代码只是用来处理
ListView
而不是
TextView
。除了
nextFocusLeft
nextFocusRight
属性外,编辑文本的其他属性没有任何更改


编辑:我刚试过Go键盘和Hacker的键盘,TAB收到的很好。这似乎只是一些虚拟键盘的问题,我想我可能已经看到了问题所在。查看ListView.java的源代码,有一种机制可以使用在列表项中转移焦点的关键事件。请检查该方法前面的注释以及方法中间的注释块。

/**
 * To avoid horizontal focus searches changing the selected item, we
 * manually focus search within the selected item (as applicable), and
 * prevent focus from jumping to something within another item.
 * @param direction one of {View.FOCUS_LEFT, View.FOCUS_RIGHT}
 * @return Whether this consumes the key event.
 */
private boolean handleHorizontalFocusWithinListItem(int direction) {
    if (direction != View.FOCUS_LEFT && direction != View.FOCUS_RIGHT)  {
        throw new IllegalArgumentException("direction must be one of"
                + " {View.FOCUS_LEFT, View.FOCUS_RIGHT}");
    }

    final int numChildren = getChildCount();
    if (mItemsCanFocus && numChildren > 0 && mSelectedPosition != INVALID_POSITION) {
        final View selectedView = getSelectedView();
        if (selectedView != null && selectedView.hasFocus() &&
                selectedView instanceof ViewGroup) {

            final View currentFocus = selectedView.findFocus();
            final View nextFocus = FocusFinder.getInstance().findNextFocus(
                    (ViewGroup) selectedView, currentFocus, direction);
            if (nextFocus != null) {
                // do the math to get interesting rect in next focus' coordinates
                currentFocus.getFocusedRect(mTempRect);
                offsetDescendantRectToMyCoords(currentFocus, mTempRect);
                offsetRectIntoDescendantCoords(nextFocus, mTempRect);
                if (nextFocus.requestFocus(direction, mTempRect)) {
                    return true;
                }
            }
            // we are blocking the key from being handled (by returning true)
            // if the global result is going to be some other view within this
            // list.  this is to acheive the overall goal of having
            // horizontal d-pad navigation remain in the current item.
            final View globalNextFocus = FocusFinder.getInstance().findNextFocus(
                    (ViewGroup) getRootView(), currentFocus, direction);
            if (globalNextFocus != null) {
                return isViewAncestorOf(globalNextFocus, this);
            }
        }
    }
    return false;
}

单个列表元素中是否有多个可聚焦的项?如果是这样,此代码将使用tab键。如果是这样的话,那么您可能希望使一些项目不可聚焦或考虑另一个设计选项。 我建立了一个测试项目来测试这一点,不幸的是它没有工作。edittext始终具有焦点,因此它应该始终接收keyevent,或者至少应该在dispatchKeyEvent中捕获它。这适用于黑客键盘,但不适用于普通键盘。我已经在这里上传了测试项目,ListView中的所有内容都设置为不可聚焦。当我在三星Galaxy SII Epic 4G上运行它时,软键盘甚至没有显示tab键。模拟器键盘也没有tab键。建议,尝试使用.setKeyListener()而不是setOnKeyListener()如果文档有任何依据,setKeyListener不适用于此