第一次单击时自动放置PlaceAutocompleteFragment

时间:2018-07-27 07:18:43

标签: android api firebase placeautocompletefragment

在将PlaceAutocompleteFragment用于自定义布局时遇到了麻烦。 第一次单击时,它只是获得焦点,而第二次单击时,它会弹出。 我在片段类里面使用过。 这是上传视频的链接。 我在自定义布局上使用了EditTextHere is demo video

MainFragment.class

PlaceAutocompleteFragment placeAutocompleteFragment = (PlaceAutocompleteFragment) getActivity().getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);
AutocompleteFilter typeFilter = new AutocompleteFilter.Builder()
//.setTypeFilter(AutocompleteFilter.TYPE_FILTER_CITIES)
.setTypeFilter(AutocompleteFilter.TYPE_FILTER_REGIONS)
.build();

placeAutocompleteFragment.setFilter(typeFilter);
placeAutocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(Place place) {
//places.setText(""+place.getAddress());
Log.d("Filtered",""+place.getId());
Log.d("Filtered",""+place.getAddress());
Log.d("Filtered",""+place.getLocale());
Log.d("Filtered",""+place.getPlaceTypes());
}

@Override
public void onError(Status status) {
}
});

CustomPlaceAutoCompleteFragment.class

public class CustomPlaceAutoCompleteFragment extends PlaceAutocompleteFragment {

private EditText editSearch;

private View zzaRh;
private View zzaRi;
private EditText zzaRj;
@Nullable
private LatLngBounds zzaRk;
@Nullable
private AutocompleteFilter zzaRl;
@Nullable
private PlaceSelectionListener zzaRm;

public CustomPlaceAutoCompleteFragment() {
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View var4 = inflater.inflate(R.layout.custom_place_auto_complete_fragment, container, false);

editSearch = (EditText) var4.findViewById(R.id.editWorkLocation);
editSearch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
zzzG();
}
});

return var4;
}


public void onDestroyView() {
this.zzaRh = null;
this.zzaRi = null;
this.editSearch = null;
super.onDestroyView();
}

public void setBoundsBias(@Nullable LatLngBounds bounds) {
this.zzaRk = bounds;
}

public void setFilter(@Nullable AutocompleteFilter filter) {
this.zzaRl = filter;
}

public void setText(CharSequence text) {
this.editSearch.setText(text);
//this.zzzF();
}

public void setHint(CharSequence hint) {
this.editSearch.setHint(hint);
this.zzaRh.setContentDescription(hint);
}

public void setOnPlaceSelectedListener(PlaceSelectionListener listener) {
this.zzaRm = listener;
}

private void zzzF() {
boolean var1 = !this.editSearch.getText().toString().isEmpty();
//this.zzaRi.setVisibility(var1?0:8);
}

private void zzzG() {
int var1 = -1;

try {
Intent var2 = (new PlaceAutocomplete.IntentBuilder(2)).setBoundsBias(this.zzaRk).setFilter(this.zzaRl).zzh(this.editSearch.getText().toString()).zzg(1).build(this.getActivity());
this.startActivityForResult(var2, 1);
} catch (GooglePlayServicesRepairableException var3) {
var1 = var3.getConnectionStatusCode();
Log.e("Places", "Could not open autocomplete activity", var3);
} catch (GooglePlayServicesNotAvailableException var4) {
var1 = var4.errorCode;
Log.e("Places", "Could not open autocomplete activity", var4);
}

if (var1 != -1) {
GoogleApiAvailability var5 = GoogleApiAvailability.getInstance();
var5.showErrorDialogFragment(this.getActivity(), var1, 2);
}

}

public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1) {
if (resultCode == -1) {
Place var4 = PlaceAutocomplete.getPlace(this.getActivity(), data);
if (this.zzaRm != null) {
this.zzaRm.onPlaceSelected(var4);
}

this.setText(var4.getName().toString());
} else if (resultCode == 2) {
Status var5 = PlaceAutocomplete.getStatus(this.getActivity(), data);
if (this.zzaRm != null) {
this.zzaRm.onError(var5);
}
}
}

super.onActivityResult(requestCode, resultCode, data);
}

}

1 个答案:

答案 0 :(得分:0)

设置城市的输入类型EditText

editText1= (EditText) super.getActivity().findViewById(R.id.editText1);
editText1.setInputType(InputType.TYPE_NULL);