I added an AutocompleteSupportFragment in an AlertDialog.
AlertDialog
I want to make sure location field is not empty after user clicks "Create" button. (Just like how I make sure other fields are not empty.)
Fields validation
I wish there is something like a setOnPlaceUnselectedListener. But AutocompleteSupportFragment only has setOnPlaceSelectedListener, which is not ideal because it won't know if user enters some location and then clears the input.
AutocompleteSupportFragment does have a setText method to set the text to display in the search input field. But it seems it doesn't have a corresponding getText method.
Is there anyway to validate whether AutocompleteSupportFragment has a Place selected or is empty? .xml
<fragment android:id="@+id/create_event_location_frag"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="com.google.android.libraries.places.widget.AutocompleteSupportFragment" />
Activity.java
autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(Place place) {
// Updating my class variables here doesn't help.
// If user first selects a place, then clears it and click "Create",
// I won't know that the location field is empty.
Log.i(TAG, "Place: " + place.getName() + ", " + place.getId());
}
@Override
public void onError(Status status) {
Log.i(TAG, "An error occurred: " + status);
}
});