Java Code Examples for android.widget.ListView#setOnKeyListener()

The following examples show how to use android.widget.ListView#setOnKeyListener() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
private void ensureList() throws RuntimeException {
    final View root = getView();
    if (root == null) {
        throw new IllegalStateException("Content view not yet created");
    }
    final View listView = root.findViewById(android.R.id.list);
    if (listView == null) {
        throw new RuntimeException("Your content must have a ListView whose id attribute is 'android.R.id.list'");
    }
    if (!(listView instanceof ListView)) {
        throw new RuntimeException("Content has view with id attribute 'android.R.id.list' that is not a ListView class");
    }
    mList = (ListView) listView;
    mList.setOnKeyListener((v, keyCode, event) -> {
        final Object selectedItem = mList.getSelectedItem();
        if (selectedItem instanceof Preference) {
            @SuppressWarnings("unused") final View selectedView = mList.getSelectedView();
            // return ((Preference) selectedItem).onKey(selectedView, keyCode, event);
            return false;
        }
        return false;
    });
    mHandler.post(mRequestFocus);
}