【发布时间】:2020-03-30 23:49:12
【问题描述】:
我在 AlertDialog 中添加了一个 AutocompleteSupportFragment。
AlertDialog
我想确保用户单击“创建”按钮后位置字段不为空。 (就像我如何确保其他字段不为空一样。)
Fields validation
我希望有类似 setOnPlaceUnselectedListener 的东西。但是 AutocompleteSupportFragment 只有 setOnPlaceSelectedListener,这并不理想,因为它不知道用户是否输入了某个位置然后清除输入。
AutocompleteSupportFragment 确实有一个 setText 方法来设置要在搜索输入字段中显示的文本。但是好像没有对应的getText方法。
是否有验证 AutocompleteSupportFragment 是否选择了 Place 或是否为空? .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);
}
});
【问题讨论】:
标签: android google-maps android-fragments google-places-api