Java android change autocompletetextview适配器内置TextWatcher

Java android change autocompletetextview适配器内置TextWatcher,java,android,web-services,autocompletetextview,Java,Android,Web Services,Autocompletetextview,我正在使用AutoCompleteTextView控件 由于数据量巨大,AutoCompleteTextView适配器通过TextWatcher onTextChanged事件中的web服务填充 但是这个解决方案并不能很好地工作,因为下拉列表有时显示,有时不显示,有时崩溃。 我试图更改为后文本更改事件,但结果相同 我已经看到了一些答案,但他们谈到从应用程序或SQLite中填充适配器 知道如何解决这些问题吗 谢谢 actvCentre = (AutoCompleteTextView) findV

我正在使用AutoCompleteTextView控件 由于数据量巨大,AutoCompleteTextView适配器通过TextWatcher onTextChanged事件中的web服务填充

但是这个解决方案并不能很好地工作,因为下拉列表有时显示,有时不显示,有时崩溃。 我试图更改为后文本更改事件,但结果相同

我已经看到了一些答案,但他们谈到从应用程序或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


    }
}
//-------------------------------------------------------------------------

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


    }
}
私有类SelectWSTask扩展异步任务{
私有字符串resp;
私有字符串CallSelectWS(String cityni)抛出IOException,XMLPullParseRexException{
WebserviceCall com=新的WebserviceCall();
字符串aResponse=com.CityAutoComplete(“CityAutoComplete”,cityni);
返回应答;
}
@凌驾
受保护的字符串doInBackground(字符串…参数){
试一试{
字符串cityni=params[0];
resp=CallSelectWS(cityni);
}捕获(IOE异常){
e、 printStackTrace();
}catch(XMLPullParseRexE){
e、 printStackTrace();
}
返回响应;
}
@凌驾
受保护的void onPostExecute(字符串结果){
}
@凌驾
受保护的void onPreExecute(){
}
@凌驾
受保护的void onProgressUpdate(字符串…文本){
}
}
//--------------------------------------------------------

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


    }
}
私有类CityAutoLoaderTask扩展异步任务{
/**在非ui线程中解析xml数据*/
@凌驾
受保护列表doInBackground(字符串…xmlData){
StringReader=新的StringReader(xmlData[0]);
MsgsXmlParser MsgsXmlParser=新的MsgsXmlParser();
/**将解析后的数据作为列表构造获取*/
List CAuto=null;
试一试{
CAuto=msgsXmlParser.parseCityAuto(读取器);
}catch(XMLPullParseRexE){
e、 printStackTrace();
}捕获(IOE异常){
e、 printStackTrace();
}
返回CAuto;
}
@凌驾
受保护的void onPostExecute(列表){
ArrayList ArrayList=新的ArrayList();
int lsize=((ArrayList)list).size();

对于(int i=0;i调用
ActvCenter.showDropDown();
onPostExecute()

显示您在
FillCityAuto()
方法中有什么