AsyncTask不会调用将空间应用于URL

时间:2014-07-25 08:12:08

标签: android android-asynctask

我正在为歌曲创建一个Google搜索应用。当用户输入歌曲名称时,AutotextView会建议您输入歌曲名称。对于每个单词更改,我必须调用AsycTaskweb service获取数据并且它完全正常工作。我有两个问题。

  1. 它的响应很慢
  2. 当我用“Waka Waka”这样的空间调用歌曲时,AsyncTask不会设置适配器
  3. 我已经尝试过其他方式来解决它。我用%20替换空格,但空间适配器没有为AutotexView设置适配器listView

    自动提交视频

    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 个答案:

没有答案