我使用BadgeView并希望在Fragment Tab OnStart时显示徽章编号。 BadgeView在FragmentActivity类中成功显示,但不知何故它没有显示出来 片段类。 请帮我... 这是我的代码
enter code here
public class Info扩展Fragment {
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
}
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
return inflater.inflate(R.layout.activity_info, container, false);
}
@Override
public void onStart() {
// TODO Auto-generated method stub
super.onStart();
TabWidget tabs = (TabWidget) getView().findViewById(android.R.id.tabs);
BadgeView badge = new BadgeView(getActivity().getApplicationContext(),tabs,2);
badge.setText("8");
badge.show();
}
}
答案 0 :(得分:1)
你应该改变这个
TabWidget tabs = (TabWidget) getView().findViewById(android.R.id.tabs);
到
TabWidget tabs = (TabWidget) getActivity().findViewById(android.R.id.tabs);