마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

자동완성 기능에 관해서~

0 추천
public class Search_By extends Activity {
AutoCompleteTextView search;
Button goSearch_Button;
private ArrayAdapter<String> autoCompAdapter;


Context context;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search);

autoCompAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line);
autoCompAdapter.setNotifyOnChange(true);

search= (AutoCompleteTextView)findViewById(R.id.serch);
search.setThreshold(2);

search.addTextChangedListener(textChecker);
search.setAdapter(autoCompAdapter);



goSearch_Button = (Button)findViewById(R.id.searchbutton);

goSearch_Button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {

Intent intent = new Intent(this, Search_list.class);

intent.putExtra("name",search.getText().toString());
startActivity(intent);
}
});
}

final TextWatcher textChecker = new TextWatcher() {

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
Log.d("onTextChanged","1");
//autoCompAdapter.clear();
HttpGetTask httpGetTask = new HttpGetTask();
httpGetTask.execute();
}

@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub

}

@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub

}
};

private void callPHP(){
Log.d("callPHP","callPHP");
String result ="";
InputStream is =null;

try{
ArrayList<NameValuePair> nameValPairs = new ArrayList<NameValuePair>();
nameValPairs.add(new BasicNameValuePair("hotel_name", search_hotel.getText().toString()));
String hotel_name=URLEncoder.encode(search_hotel.getText().toString(),"UTF-8");
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://test.com/text/json.php"
+"?flag=6"+"&"+"hotel_name="+hotel_name);
httppost.setEntity(new UrlEncodedFormEntity(nameValPairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();


}catch(UnsupportedEncodingException e) {
e.printStackTrace();
}catch(ClientProtocolException e) {
e.printStackTrace();
}catch(IOException e) {
e.printStackTrace();
}catch(Exception e){
e.printStackTrace();
Log.e("Log_TAG","Error in http connection " + e.toString());
}

try{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"UTF-8"),8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null){
sb.append(line +"\n");
}
is.close();

result=sb.toString();
}catch(Exception e){
Log.e("Log_TAG","Error in http connection " + e.toString());
}

try{
JSONArray jArray = new JSONArray(result);
for(int i=0;i<jArray.length();i++){
JSONObject json_data = jArray.getJSONObject(i);
Log.d("json_data",json_data.getString("name"));
autoCompAdapter.add(json_data.getString("name"));
}
}catch(JSONException e){
Log.e("Log_TAG","Error parsing data"+e.toString());
}
}

public class HttpGetTask extends AsyncTask<Void, Void, String> {
String url = "";
public HttpGetTask() {
super();
}
public HttpGetTask(String latitude, String longitude) {
super();
}
public HotelInfomastion_Get_Seters data;
protected String doInBackground(Void... Void) {
String result = "";

callPHP();
return result;
}

protected void onPreExecute(){

}
protected void onPostExecute(String response) {
}

}

}
위에가 소스 코드구요~ 제가 하고싶은건
 
autocompleteTextView에 안드로이드 라고 치면 칠때마다 json.php에 치고 있는 글자를 날려
자동완성기능을 보여주고싶은데요
 
일단 칠때마다 json으로 잘읽어 오고 있다는건
 
Log.d("json_data",json_data.getString("name"));를 통해서 알겠는데요
 
여기까진 다 잘되는데
 
자동완성 목록이 뜨질않네요 ...불러오는건 되는데 목록이 뜨질 않아서, 뭐가 문제인지 잘모르겠네요.
 
선배님들 조언 잘부탁드리겠습니다 .ㅠ

 

 

익명사용자 님이 2013년 8월 3일 질문

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...