AsyncTask does not require space to be applied to the URL

I create a Googlesearch, for example, for compositions. while the user enters the name of the song, AutotextViewoffers you the name of the song. For every change in the word, I have to call AsycTaskto get the data from web service, and it works fine. I have two problems.

  • The answer is slow.
  • AsyncTask does not install the adapter when I call a song with a space like "Waka Waka"

I tried another way to solve it. I am replacing a space %20, but still the adapter for space does not set up a list of adapters for AutotexView

Autotextview

textView.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence cs, int arg1, int arg2,
                int arg3) {

            seq = cs;

        }

        @Override
        public void beforeTextChanged(CharSequence s, int arg1, int arg2,
                int arg3)
        {

        }

        @Override
        public void afterTextChanged(Editable arg0)
        {
            if(mAsync!=null) {
                mAsync.cancel(true);
            }
            //new SearchTask().execute(seq.toString().trim());
             mAsync =(SearchTask) new SearchTask().execute(seq.toString());
        }
    });

SearchTask

private class SearchTask extends AsyncTask<CharSequence, Void, String> 
    {
        ArrayAdapter<String> adapter;

        String[] array;

        @Override
        protected String doInBackground(CharSequence... params) 
        {
            try {
                HttpClient httpclient = new DefaultHttpClient();

                HttpPost httppost = new HttpPost(pak_url + params[0]);

                HttpResponse responce = httpclient.execute(httppost);

                HttpEntity httpEntity = responce.getEntity();

                String response = EntityUtils.toString(httpEntity);

                Log.d("response is", response);

                if (response != null) {
                    String substr = response.split("\\(")[2].split("\\)")[0];

                    array = substr.split(",");

                    for (int i = 0; i < array.length; i++) {

                        array[i] = array[i].replace("'", "");
                    }

                }

                return response;
            } catch (Exception e) {
                e.printStackTrace();
            }

            return null;
        }

        @Override
        protected void onPostExecute(String result) {
            super.onPostExecute(result);

            if (array != null) {
                adapter = new ArrayAdapter<String>(PlayListActivity.this,
                        android.R.layout.simple_list_item_1, array);

                textView.setAdapter(adapter);

                adapter.getFilter().filter(seq);
            } 
        }
    }

- , AsyncTask. - . , AsyncTask .

0

All Articles