我尝试从在文本框中键入的基于 Web 服务的文本更新自动完成文本视图数据。它工作正常,但我在 Web 服务调用时放置了进度条,因为在这种情况下,自动完成文本视图不显示下拉菜单需要一些时间。我猜自动完成文本视图在进度条被解雇时被解雇。在这种情况下我们应该如何放置进度条。
Code
类 GetFundNames 扩展 AsyncTask {
ProgressDialog progress = new ProgressDialog(BasicAutoText.this);
@Override
protected void onPreExecute() {
Log.d("TAG", "onPreExecute()");
progress.setMessage("Please wait...");
progress.setCanceledOnTouchOutside(false);
progress.show();
}
@Override
// three dots is java for an array of strings
protected String doInBackground(Void... args) {
try {
response = getNames(strKeyword);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
;
return response;
}
// then our post
@Override
protected void onPostExecute(String response) {
if(progress.isShowing())
{
progress.dismiss();
}
if (ETF_Constants.registerResponsevalue == 200) {
JSONArray arObjects;
try {
arObjects = new JSONArray(response);
arProducts = new ArrayList<ProductData>();
arProducts.clear();
for (int i = 0; i < arObjects.length(); i++) {
JSONObject jOb = arObjects.getJSONObject(i);
ProductData pd = new ProductData();
int fundId = jOb.getInt("fundId");
String con = "" + fundId;
String fundName = jOb.getString("fundName");
String priceAndDate = jOb.getString("priceAndDate");
String recentGain = jOb.getString("recentGain");
String recentGrowth = jOb.getString("recentGrowth");
String tickerName = jOb.getString("tickerName");
pd.fundId = con;
pd.fundName = fundName;
pd.priceAndDate = priceAndDate;
pd.recentGain = recentGain;
pd.recentGrowth = recentGrowth;
pd.tickerName = tickerName;
arProducts.add(pd);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// autocomplete
adapter = new ArrayAdapter<String>(BasicAutoText.this,
R.layout.advancelist);
adapter.setNotifyOnChange(true);
AUTO_View.setAdapter(adapter);
System.out.println("adapter" + adapter);
for (int i = 0; i < arProducts.size(); i++) {
adapter.add(arProducts.get(i).fundName);
System.out.println("Fund Name:"
+ arProducts.get(i).fundName);
}
System.out.println("arProducts count:" + arProducts.size());
System.out.println("adapter count:" + adapter.getCount());
adapter.notifyDataSetChanged();
}
}
}