当前位置: 代码迷 >> Android >> fragment里边按钮的事件里getActivity.sendBroadcast无法使用
  详细解决方案

fragment里边按钮的事件里getActivity.sendBroadcast无法使用

热度:28   发布时间:2016-04-28 04:12:27.0
fragment里面按钮的事件里getActivity.sendBroadcast无法使用。
代码这样的:
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);

button_refresh = (ImageButton) view.findViewById(R.id.imageButton1_1);
//添加刷新按鈕
button_refresh.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {

sendMessage();
Intent updateIntent = new Intent("com.neusoft.weather.UPDATA_WEATHER");
//getActivity().sendBroadcast(intent);!!!!看这里。

}
});
重写的 onActivityCreated的方法。但是在 按钮里  空指针。。get得不到东西。
这就神奇啊。onActivityCreated 应该是在onCreate之后啊。。求指教。。
------解决方案--------------------
看到你使用了view.findViewById,想问下你有没有view有没有进行初始化
  相关解决方案