2014-07-10 3 views
0

AutoCompleteTextView 컨트롤은 TextWatcher onTextChanged 이벤트 내에서 웹 서비스를 통해 AutoCompleteTextView 어댑터가 채워지는 거대한 데이터로 인해 AutoCompleteTextView 컨트롤 을 사용하고 있습니다.TextWatcher 안드로이드 변경 autocompletetextview 어댑터

그러나이 솔루션은 실제로 제대로 작동하지 않습니다. 드롭 다운이 때로는 때때로 나타나지 않고 때로는 충돌하기 때문에. 내가 어떤 대답을 보았다

afterTextChanged 이벤트하지만 같은 결과로 변경하려고하지만, 앱 내에서 어댑터를 채우거나 SQLite는

내가

을 데 이러한 문제를 해결하는 방법에 어떤 아이디어에 대해 이야기 감사합니다

actvCentre = (AutoCompleteTextView) findViewById(R.id.actvCentre); 
     actvCentre.addTextChangedListener(new TextWatcher() { 

      @Override 
      public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { 

      } 

      @Override 
      public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { 
       FillCityAuto(charSequence.toString()); 
       actvCentre.showDropDown(); 
      } 

      @Override 
      public void afterTextChanged(Editable editable) { 


      } 
     }); 

// ---------------------------------------- ----------------

private void FillCityAuto(String CityIni) 
{ 
    String sXML=""; 

    // Get XML from Web Service 
    try 
    { 
     SelectWSTask selectWSTask = new SelectWSTask(); 
     sXML = selectWSTask.execute(CityIni).get(); 

    } catch (InterruptedException e) { 
     e.printStackTrace(); 
    } catch (ExecutionException e) { 
     e.printStackTrace(); 
    } 

    /** The parsing of the xml data is done in a non-ui thread */ 
    CityAutoLoaderTask caLoaderTask = new CityAutoLoaderTask(); 

    caLoaderTask.execute(sXML); 

} 

// --------------------------------------------- ----------------------------

private class SelectWSTask extends AsyncTask<String, String, String> { 

    private String resp; 

    private String CallSelectWS(String CityIni) throws IOException, XmlPullParserException { 

     WebserviceCall com = new WebserviceCall(); 

     String aResponse = com.CityAutoComplete("CityAutoComplete", CityIni); 

     return aResponse; 
    } 

    @Override 
    protected String doInBackground(String... params) { 
     try { 
      String CityIni = params[0]; 

      resp = CallSelectWS(CityIni); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } catch (XmlPullParserException e) { 
      e.printStackTrace(); 
     } 
     return resp; 
    } 

    @Override 
    protected void onPostExecute(String result) { 

    } 

    @Override 
    protected void onPreExecute() { 

    } 


    @Override 
    protected void onProgressUpdate(String... text) { 

    } 
} 

// ------------- -------------------------------------------

private class CityAutoLoaderTask extends AsyncTask<String, Void, List<HashMap<String, String>>>{ 

    /** Doing the parsing of xml data in a non-ui thread */ 
    @Override 
    protected List<HashMap<String, String>> doInBackground(String... xmlData) { 
     StringReader reader = new StringReader(xmlData[0]); 


     MsgsXmlParser msgsXmlParser = new MsgsXmlParser(); 



      /** Getting the parsed data as a List construct */ 
     List<HashMap<String, String>> CAuto = null; 
     try { 
      CAuto = msgsXmlParser.parseCityAuto(reader); 
     } catch (XmlPullParserException e) { 
      e.printStackTrace(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 


     return CAuto; 
    } 

    @Override 
    protected void onPostExecute(List<HashMap<String, String>> list) { 

     ArrayList<String> arrayList = new ArrayList<String>(); 
     int lsize = ((ArrayList) list).size(); 
     for (int i=0; i<lsize;i++) { 
      HashMap<String, String> firstMap = list.get(i); 
      String City = firstMap.get("City"); 
      arrayList.add(City); 
     } 
     //String a = ""; 
     arrayAdapter = null; 
     arrayAdapter = new ArrayAdapter<String>(ListFilter.this, android.R.layout.simple_list_item_1, arrayList); 
     arrayAdapter.notifyDataSetChanged(); 
     actvCentre.setAdapter(arrayAdapter); 

     // save index and top position 


    } 
} 
+0

으로 표시하십시오. 'FillCityAuto()'메소드에 무엇이 있는지 보여주세요. – intrepidkarthi

+0

위의 코드를 추가했습니다. – asmgx

답변

1

actvCentre.showDropDown();onPostExecute()