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中绑定button报错 #6

Closed
star-andy opened this issue Feb 14, 2017 · 14 comments
Closed

在fragment中绑定button报错 #6

star-andy opened this issue Feb 14, 2017 · 14 comments

Comments

@star-andy
Copy link

image

@qstumn
Copy link
Owner

qstumn commented Feb 14, 2017

您能贴全一点的log么,单看这个不知道怎么回事

@star-andy
Copy link
Author

刚才吃饭去了,不好意思
image

@qstumn
Copy link
Owner

qstumn commented Feb 14, 2017

Badge和TargetView绑定是采用的换掉TargetView的Parent实现的,绑定后给此Parent设置了和TargetView同样的id,这时通过findViewById找出来的是TargetView的Parent,如果您需要获得TargetView的对象,可以用此Parent再次findViewById,或者Badge.getTargetView来获得,已在1.0.5版本中添加此方法,感谢您的反馈

@star-andy
Copy link
Author

那我该怎么使用来解决这个闪退问题呢?

@qstumn
Copy link
Owner

qstumn commented Feb 14, 2017

如果尚未绑定,使用findViewById,已绑定使用Badge.getTargetView

@star-andy
Copy link
Author

能麻烦你在demo上写个例子吗?我没太明白你表达的 我现在在fragment中先初始化了button 然后把button绑定了 你的意思是在绑定后给badview设置属性时需要使用Badge.getTargetView是这样吗?

@qstumn
Copy link
Owner

qstumn commented Feb 14, 2017

可否把你出错的initViews 151行这附近的代码贴出来,我看下怎么改,不方便在这贴可以发到我的邮箱qstumn@163.com

@star-andy
Copy link
Author

image

@qstumn
Copy link
Owner

qstumn commented Feb 14, 2017

你的initViews除了在onCreateView方法中调用之外,是否在其他地方又调用了

@star-andy
Copy link
Author

不是在oncreate调用的 我这个fragment是在viewpager里面 使用的懒加载
image

@qstumn
Copy link
Owner

qstumn commented Feb 14, 2017

您可以看下此方法是否被回调了不止一次,如果是这样,建议152行改为
if(mBadge!=null&&mBadge.getTargetView()!=null&&mBadge.getTargetView().getId()==R.id.system_setting){
mSystemSetting = (Button)mBadge.getTargetView();
}else{
mSystemSetting = (Button)rootView.findViewById(R.id.system_setting);
mBadge=new QBadgeView(getActivity()).bindTarget(mSystemSetting);
}
180~185改成
mBadge.setBadgeGravity(Gravity.END|Gravity.TOP).setBadgeNumberSize(0,true).setBadgeBackgroundColor(0xffEF5350).setGravityOffset(5,true).setBadgeNumber(5);

@star-andy
Copy link
Author

确实是回调了两次 我把这个改了 现在回调一次后就正常了,谢谢了
这个能在你库源码的级别加个限制吗? 或者捕获下这个异常打印个log也让其他使用者知道是这个问题

@qstumn
Copy link
Owner

qstumn commented Feb 14, 2017

BadgeView和TargetView绑定是采用的换掉TargetView的Parent实现的,暂时我没有更完美的解决方法,感谢你的反馈提醒,如果您找到更好的方法并愿意分享希望到时能告诉我

@star-andy
Copy link
Author

好的 谢谢你了,我close了

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