我正在为歌曲创建一个Google
搜索应用。当用户输入歌曲名称时,AutotextView
会建议您输入歌曲名称。对于每个单词更改,我必须调用AsycTask
从web service
获取数据并且它完全正常工作。我有两个问题。
我已经尝试过其他方式来解决它。我用%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
不会得到数据。