如何在 Fragments 中使用 Google API 客户端
How to user GoogleAPI Client in Fragments
我无法在 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();
}
}
它显示错误:
只需切换 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 语句应该始终是方法中的最后一行。
我无法在 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();
}
}
它显示错误:
只需切换 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 语句应该始终是方法中的最后一行。