public class Places_DATA extends ActionBarActivity
{
private GoogleApiClient mGoogleApiClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_places);
mGoogleApiClient = new GoogleApiClient
.Builder(this)
.addApi(Places.GEO_DATA_API)
.addApi(Places.PLACE_DETECTION_API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
问题是我一直收到.addConnectionCallbacks(this)的错误。该错误表明.ConnectionCallbacks无法添加到类中。我不确定我做错了什么,因为我一直关注谷歌的文档,如下所示:https://developers.google.com/places/android/start
答案 0 :(得分:9)
除非this
和ConnectionCallbacks
,否则您无法使用OnConnectionFailedListener
。您可以通过让您的活动实现这些接口来实现这一目标。
public class Places_DATA extends ActionBarActivity
implements ConnectionCallbacks, OnConnectionFailedListener {
private GoogleApiClient mGoogleApiClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_places);
mGoogleApiClient = new GoogleApiClient
.Builder(this)
.addApi(Places.GEO_DATA_API)
.addApi(Places.PLACE_DETECTION_API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
@Override
public void onConnected(Bundle connectionHint) {
// We are now connected!
}
@Override
public void onConnectionSuspended(int cause) {
// We are not connected anymore!
}
@Override
public onConnectionFailed(ConnectionResult result) {
// We tried to connect but failed!
}
}