Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onCreateView返回0时setCallBack出错 #139

Open
Pacey6 opened this issue Jun 29, 2020 · 4 comments
Open

onCreateView返回0时setCallBack出错 #139

Pacey6 opened this issue Jun 29, 2020 · 4 comments

Comments

@Pacey6
Copy link

Pacey6 commented Jun 29, 2020

若仿照自带HintCallback那样在onCreateView中返回0,则:
loadService.setCallBack(HintCallback.class, (context, view1) -> {});
报错找不到资源0x00

@KingJA
Copy link
Owner

KingJA commented Jul 24, 2020

@Pacey6 你好,可能注册时机不对,请参照Demo

@teaim
Copy link

teaim commented Jul 28, 2020

@KingJA 测试发现, 必须先执行showCallback, 再执行setCallback才不会报"onCreateView中返回0"的异常

@teaim
Copy link

teaim commented Jul 28, 2020

因为不执行show的, HintCallback的View不会添加上去, 此时的rootView为null, 默认会走inflate通过onCreateView获取布局id进行填充, 但是HintCallback不是通过布局生成View, 而是通过代码创建的View, 所以一定会报报"onCreateView中返回0"的异常

@teaim
Copy link

teaim commented Jul 28, 2020

感觉可以和getRootView一样

    public View getRootView() {
        int resId = onCreateView();
        if (resId == 0 && rootView != null) {
            return rootView;
        }

        if (onBuildView(context) != null) {
            rootView = onBuildView(context);
        }

        if (rootView == null) {
            rootView = View.inflate(context, onCreateView(), null);
        }
        rootView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onReloadEvent(context, rootView)) {
                    return;
                }
                if (onReloadListener != null) {
                    onReloadListener.onReload(v);
                }
            }
        });
        onViewCreate(context, rootView);
        return rootView;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants