我无法在Fragment中使用Google API客户端。
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.layout_case_summary, container, false);
initView(rootView);
return rootView;
if(mGoogleApiClient==null) {
mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}
}
答案 0 :(得分:0)
只需切换return语句和google API客户端初始化:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.layout_case_summary, container, false);
initView(rootView);
if(mGoogleApiClient==null) {
mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}
return rootView;
}
return语句应始终是方法中的最后一行。