PlaceAutocompleteFragment实现正常,因为它应该工作。点击PlaceAutocompleteFragment,我可以搜索地点。
PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment)
getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);
autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(Place place) {
Toast.makeText(AroundMe.this, "" + place.getName(), Toast.LENGTH_SHORT).show();
}
@Override
public void onError(Status status) {
Toast.makeText(AroundMe.this, "" + status, Toast.LENGTH_SHORT).show();
}
});
点击搜索结果项列表后,我可以在onPlaceSelected()方法中获取地方详情。
以下是我要找的内容:
我已经尝试过这种方式,但它无法正常工作。
EditText editText = (EditText) autocompleteFragment.getActivity().findViewById(R.id.place_autocomplete_search_input);
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
Toast.makeText(AroundMe.this, "check", Toast.LENGTH_SHORT).show();
}
return false;
}
});
也尝试过这种方式,但它仍无法正常工作。
EditText editText = (EditText) autocompleteFragment.getActivity().findViewById(R.id.place_autocomplete_search_input);
editText.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
if (keyEvent.getAction()== KeyEvent.KEYCODE_SEARCH){
switch (keyCode){
case KeyEvent.KEYCODE_SEARCH:
Toast.makeText(AroundMe.this, "check" , Toast.LENGTH_SHORT).show();
break;
}
}
return false;
}
});