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

Fragment中如果用到了ButterKnife, 会产生异常 #7

Closed
weizai opened this issue Sep 27, 2017 · 7 comments
Closed

Fragment中如果用到了ButterKnife, 会产生异常 #7

weizai opened this issue Sep 27, 2017 · 7 comments

Comments

@weizai
Copy link

weizai commented Sep 27, 2017

@OverRide
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(getLayoutId(), container, false);
unbinder = ButterKnife.bind(this, rootView);
loadService = LoadSir.getDefault().register(rootView, new Callback.OnReloadListener() {
@OverRide
public void onReload(View v) {
// retry logic
}
});
return loadService.getLoadLayout();
}

试下这段代码,然后在业务Fragment中通过@BindView(R.id.xxxx) View view1, 在调用view1的地方会产生空指针。

@KingJA
Copy link
Owner

KingJA commented Sep 27, 2017

@weizai 你好,我按你的场景做了一个简单的Demo,你可以看下,是可以正常配合ButterKnife使用的。https://github.com/KingJA/LoadSirDebug

@KingJA KingJA closed this as completed Sep 27, 2017
@KingJA
Copy link
Owner

KingJA commented Sep 27, 2017

@weizai 如果有好的封装方式,也请分享下,谢谢哒

@weizai
Copy link
Author

weizai commented Sep 27, 2017

@KingJA hi, demo看了下,问题出现在onCreateView中调用loadService.showCallback(EmptyCallback.class);, 改成loadService.showSuccess()就OK了。 考虑是EmptyCallback导致上一步的rootView被移除掉了?

@weizai
Copy link
Author

weizai commented Sep 27, 2017

希望能添加类似setCallBack(CallBack.class, Object bundle)方法,便于动态改变callback中view的属性

@KingJA
Copy link
Owner

KingJA commented Sep 27, 2017

@weizai 感谢你的建议,你能否能粗略提个PR,我大概理解下你的需求,或者详细描述下你的使用场景。

@weizai
Copy link
Author

weizai commented Sep 27, 2017

ok,我把场景详细描述下吧,比如在全局注册了一个EmptyCallback,在Fragment中执行A操作后显示空数据状态“没有数据哦”,执行B操作后显示空数据状态“暂无数据”,就是说注册的CallBack需要改变view状态,属性等. 我想通过传参数解决。loadsir可以通过注册2个不同的EmptyCallback解决,但感觉不太优雅。

@KingJA
Copy link
Owner

KingJA commented Sep 27, 2017

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

2 participants