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

后端 未结 15 1597
北恋
北恋 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:08

    try this

     @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        //abandon current focus
        View currentFocus = ((Activity)mContext).getCurrentFocus();
        if (currentFocus != null) {
            currentFocus.clearFocus();
        }
    
        // other code
    }
    

    EDIT:

    See also: Better Solution

提交回复
热议问题