내지도 페이지에 AutoCompleteTextView
이 있습니다. 그것은 완벽하게 잘 작동하고 예상되는 옵션은 내가 원하는 방법입니다. 그러나 사용자가 예상 검색어 중 하나를 클릭하거나 자신의 주소를 입력하면 AutoComplete
보기의 주소를 문자열로 변경하고이를 기반으로 위도와 경도를 가져옵니다.AutoCompleteTextView setOnKeyListener가 실행되고 있지 않습니다.
public static JSONObject getLocationInfo(String address) {
StringBuilder stringBuilder = new StringBuilder();
try {
address = address.replaceAll(" ","%20");
HttpPost httppost = new HttpPost("http://maps.google.com/maps/api/geocode/json?address=" + address + "&sensor=false");
HttpClient client = new DefaultHttpClient();
HttpResponse response;
stringBuilder = new StringBuilder();
response = client.execute(httppost);
HttpEntity entity = response.getEntity();
InputStream stream = entity.getContent();
int b;
while ((b = stream.read()) != -1) {
stringBuilder.append((char) b);
}
} catch (ClientProtocolException e) {
} catch (IOException e) {
}
JSONObject jsonObject = new JSONObject();
try {
jsonObject = new JSONObject(stringBuilder.toString());
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return jsonObject;
}
그러나이 코드는 작동하지 않습니다 : 나는 그가 다음과 같이 내 getLocationInfo
방법은이
from_loc = (AutoCompleteTextView) findViewById(R.id.from_address);
from_loc.setAdapter(new PlacesAutoCompleteAdapter(this, R.layout.list_item));
from_loc.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_ENTER){
JSONObject startObj = new JSONObject();
startObj = getLocationInfo(from_loc.getText().toString());
try {
double start_lat = ((JSONArray)startObj.get("results")).getJSONObject(0)
.getJSONObject("geometry").getJSONObject("location")
.getDouble("lng");
double start_long = ((JSONArray)startObj.get("results")).getJSONObject(0)
.getJSONObject("geometry").getJSONObject("location")
.getDouble("lat");
MarkerOptions marker = new MarkerOptions().position(new LatLng(start_lat, start_long)).title("Place1");
map.addMarker(marker);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}
return false;
}
});
내 코드는 다음 keyboardThe에 완료 버튼을 누를 때이 작업을 수행 할 수 싶습니다. AutoComplete
텍스트보기의 텍스트를 다른 일반 텍스트보기로 표시하려고 시도했을 때도 발생하지 않았습니다. 사실 코드를 디버깅 할 때, 나는 결코 from_loc.setOnKeyListener
부분 안에 들어가는 것이 아니라 무엇을해야하는지 알지 못한다는 것을 깨달았습니다. 심지어 Adapter
에 대해 Listener
을 구현하려했지만 아무 일도 없었습니다.