После нескольких часов попыток решить эту проблему самостоятельно (безрезультатно) я решил попросить экспертов!
Потому что проблема в том, что результат от 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);
}
}
});
}
}