Preventing/catching “IllegalArgumentException: parameter must be a descendant of this view” error

后端 未结 15 1596
北恋
北恋 2020-11-27 13:46

I have a ListView with some focusable components inside (mostly EditTexts). Yeah, I know this isn\'t exactly recommended, but in general, almost everything is w

15条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-27 14:17

    I am sorry to tell you, I found my previous answer isn't the most perfect way to solve this problem.

    So i try this :
    Append a ScrollListener to your Activity, when listView start scrolling, clear current focus.

    protected class MyScrollListener implements OnScrollListener {
    
            @Override
            public void onScroll(AbsListView view, int firstVisibleItem,
                    int visibleItemCount, int totalItemCount) {
                // do nothing 
            }
    
            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {
                if (SCROLL_STATE_TOUCH_SCROLL == scrollState) {
                    View currentFocus = getCurrentFocus();
                    if (currentFocus != null) {
                        currentFocus.clearFocus();
                    }
                }
            }
    
        }
    

提交回复
热议问题