我有三个由三个按钮组成的无线电组。每个按钮执行不同的搜索。发生的事情是当我首先选择用户进行搜索时,然后我选择场地,然后对用户和场地进行搜索,然后首先显示用户列表并快速切换到场地列表。我怎样才能防止这种情况发生?当我选择下一个单选按钮时,它不应该在搜索上一个按钮时执行并显示两个列表结果。我已经包含了一些代码片段:UserSearch,UserSearch Adapter。 VenueSearchAdapter和VenueSearch完全相同。任何帮助是极大的赞赏。
public class UserSearchAdapter extends BaseAdapter {
private LayoutInflater inflater;
private Context context;
public UserSearchAdapter(Context context, ArrayList<HashMap<String, String>> searchList) {
inflater = LayoutInflater.from(context);
this.context = context;
}
public int getCount() {
return searchList.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public void clearLists() {
searchList.clear();
notifyDataSetChanged();
}
public View getView(int position, View convertView, ViewGroup parent) {
inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.activity_ulist, null);
class UserSearch extends AsyncTask<String, String, String> {
protected String doInBackground(String... args) {
//updating UI from Background Thread
String input = userInput.getText().toString();
String type = "user";
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
if(input != ""){
params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("userInput",input.concat("%")));
params.add(new BasicNameValuePair("searchType", type));
}
// getting JSON string from URL
JSONObject json = jParser.makeHttpRequest(Search_URL, "POST", params);
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url) {
// dismiss the dialog after getting all orders
//pDialog.dismiss();
// updating UI from Background Thread
runOnUiThread(new Runnable() {
public void run() {
/**
* Updating parsed JSON data into ListView
* */
list = (ListView)getListView().findViewById(android.R.id.list);
uadapter=new UserSearchAdapter(SearchButtonActivity.this, searchList);
list.setAdapter(uadapter);
if(userInput.length() == 0)
list.setAdapter(null);
}
});
}
}