几个小时后,我自己尝试解决此问题(没有任何结果),我决定寻求专家!
因为问题是因为API的结果运行良好,但是当我在结果行中单击以自动完成EditText txtDestination和txtsourceAddress时,这些字段不会被替换为所触摸的信息。
有人可以帮助解决这个问题吗?我将非常感谢您的帮助。
在无效的代码下面:
mAutoCompleteList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (txtaddressSource.getText().toString().equalsIgnoreCase("")) {
try {
AlertDialog.Builder builder = new AlertDialog.Builder(thisActivity);
LayoutInflater inflater = (LayoutInflater) thisActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
builder.setMessage("PLEASE CHOOSE A ADDRESS")
.setTitle(thisActivity.getString(R.string.app_name))
.setCancelable(true)
.setIcon(R.mipmap.ic_launcher)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
txtaddressSource.requestFocus();
txtDestination.setText("");
imgDestClose.setVisibility(View.GONE);
mAutoCompleteList.setVisibility(View.GONE);
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();
} catch (Exception e) {
e.printStackTrace();
}
} else {
setGoogleAddress(position);
}
}
});
private void setGoogleAddress(int position) {
if (mGoogleApiClient != null) {
utils.print("", "Place ID == >"+ predictions.getPlaces().get(position).getPlaceID());
Places.GeoDataApi.getPlaceById(mGoogleApiClient, predictions.getPlaces().get(position).getPlaceID())
.setResultCallback(new ResultCallback<PlaceBuffer>() {
@Override
public void onResult(PlaceBuffer places) {
if (places.getStatus().isSuccess()) {
Place myPlace = places.get(0);
LatLng queriedLocation = myPlace.getLatLng();
Log.v("Latitude is", "" + queriedLocation.latitude);
Log.v("Longitude is", "" + queriedLocation.longitude);
if (strSelected.equalsIgnoreCase("destination")) {
placePredictions.strDestAddress = myPlace.getAddress().toString();
placePredictions.strDestLatLng = myPlace.getLatLng().toString();
placePredictions.strDestLatitude = myPlace.getLatLng().latitude + "";
placePredictions.strDestLongitude = myPlace.getLatLng().longitude + "";
txtDestination.setText(placePredictions.strDestAddress);
Log.v("setGoogleAddress onResult IF destination ", placePredictions.strDestAddress);
txtDestination.setSelection(0);
} else {
placePredictions.strSourceAddress = myPlace.getAddress().toString();
placePredictions.strSourceLatLng = myPlace.getLatLng().toString();
placePredictions.strSourceLatitude = myPlace.getLatLng().latitude + "";
placePredictions.strSourceLongitude = myPlace.getLatLng().longitude + "";
txtaddressSource.setText(placePredictions.strSourceAddress);
Log.v("setGoogleAddress onResult else ", placePredictions.strSourceAddress);
txtaddressSource.setSelection(0);
txtDestination.requestFocus();
mAutoCompleteAdapter = null;
}
} else {
Log.v("setGoogleAddress ELSE ", mAutoCompleteList.toString());
}
mAutoCompleteList.setVisibility(View.GONE);
if (txtDestination.getText().toString().length() > 0) {
places.release();
if (strSelected.equalsIgnoreCase("destination")) {
if (!placePredictions.strDestAddress.equalsIgnoreCase(placePredictions.strSourceAddress)) {
setAddress();
} else {
utils.showAlert(thisActivity, getResources().getString(R.string.source_and_destination_not_same));
}
}
} else {
txtDestination.requestFocus();
txtDestination.setText("");
imgDestClose.setVisibility(View.GONE);
mAutoCompleteList.setVisibility(View.GONE);
}
}
});
}
}