我试图在我的活动中设置搜索视图,当用户在搜索视图上键入搜索关键字时,我每次都需要将值传递给异步任务。我想从这个方法中传递参数'query‘
public boolean onQueryTextChange(String query) {
//want this 'string query' for further processing..
return true;对于此LoadIdioms class>>String doinBackground>> To line>> params.add(新BasicNameValuePair(“关键字”,查询));
class LoadIdioms extends AsyncTask<String, String, String> {
/**
* Before starting background thread Show Progress Dialog
* */
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(getActivity());
pDialog.setMessage("Loading IDIOMS. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
/**
* getting Idioms from url
* */
protected String doInBackground(String... args) {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
//value captured from previous intent
params.add(new BasicNameValuePair("keyword",query));
class LoadIdioms extends AsyncTask<String, String, String> {
/**
* Before starting background thread Show Progress Dialog
* */
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(getActivity());
pDialog.setMessage("Loading IDIOMS. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
/**
* getting Idioms from url
* */
protected String doInBackground(String... args) {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
//value captured from previous intent
params.add(new BasicNameValuePair("keyword",searchkey)); 我们怎么能轻松地做到这一点,帮助我的程序员..
发布于 2015-03-22 07:50:36
最后,我决定把我的编码变成这样。
public boolean onQueryTextChange(String query) {
searchkey=query;
new LoadIdioms().execute();
lv = getListView();
return true;在这里,我在onquerytextchange方法中调用异步任务类,所以每次发生文本更改时,它都会调用,而不是传递参数值。
发布于 2015-03-21 16:26:25
将该方法返回的布尔值传递到声明的字符串变量中。然后你可以试着在那门课上叫它。
发布于 2015-03-21 16:31:12
以这种方式将值传递到AsyncTask
LoadIdioms task= new LoadIdioms();
task.execute(query);并以这种方式在AsyncTask的AsyncTask方法中使用。
params.add(new BasicNameValuePair("keyword",args[0]));https://stackoverflow.com/questions/29184890
复制相似问题