Adding more than one Google autocomplete activity

suggest change
public static final int PLACE_AUTOCOMPLETE_FROM_PLACE_REQUEST_CODE=1;
  public static final int PLACE_AUTOCOMPLETE_TO_PLACE_REQUEST_CODE=2;

fromPlaceEdit.setOnClickListener(new View.OnClickListener() {
               @Override
               public void onClick(View v) {

                   try {
                       Intent intent = new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_FULLSCREEN)
                               .build(MainActivity.this);
                       startActivityForResult(intent, PLACE_AUTOCOMPLETE_FROM_PLACE_REQUEST_CODE);

                   } catch (GooglePlayServicesRepairableException e) {
                       // TODO: Handle the error.
                   } catch (GooglePlayServicesNotAvailableException e) {
                       // TODO: Handle the error.
                   }
               }
           });
toPlaceEdit.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {

               try {
                   Intent intent = new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_FULLSCREEN)
                           .build(MainActivity.this);
                   startActivityForResult(intent, PLACE_AUTOCOMPLETE_TO_PLACE_REQUEST_CODE);

               } catch (GooglePlayServicesRepairableException e) {
                   // TODO: Handle the error.
               } catch (GooglePlayServicesNotAvailableException e) {
                   // TODO: Handle the error.
               }
           }
       });
@Override
   protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      if (requestCode == PLACE_AUTOCOMPLETE_FROM_PLACE_REQUEST_CODE) {
          if (resultCode == RESULT_OK) {
             // Handle a successful from-place result.
          } else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {
             // Handle a from-place error.
          } else if (resultCode == RESULT_CANCELED) {
              // The user canceled the operation.
          }
      } else if (requestCode == PLACE_AUTOCOMPLETE_TO_PLACE_REQUEST_CODE) {
          if (resultCode == RESULT_OK) {
             // Handle a successful to-place result.
          } else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {
             // Handle a to-place error.
          } else if (resultCode == RESULT_CANCELED) {
              // The user canceled the operation.
          }
       }
   }

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents