【发布时间】:2013-12-09 09:28:06
【问题描述】:
我正在开发一个应用程序,用于显示从 Web 服务获取的数据到列表视图。实际上,根据我的应用程序:当用户从列表视图中单击一个项目时,应该询问一些带有对话框的消息。当用户按“是”时,会发生 Web 服务调用过程。所以..我想显示一个进度对话框,直到 Web 服务调用过程完成(用于调用 Web 服务的方法返回一个字符串消息。我想在此进度对话框关闭后显示该消息)。
我正在适配器类的 getview 方法中编写这些代码。
这是我的代码
public View getView(final int position, View convertView, final ViewGroup parent) {
// TODO Auto-generated method stub
View vi = convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.dialog_row,null);
//final TextView firstname = (TextView) vi.findViewById(R.id.fname);
//final TextView lastname = (TextView) vi.findViewById(R.id.lname);
final TextView startTime = (TextView) vi.findViewById(R.id.stime2);
final TextView endTime = (TextView) vi.findViewById(R.id.etime2);
final TextView date = (TextView) vi.findViewById(R.id.blank2);
final TextView uid = (TextView) vi.findViewById(R.id.lname2);
final TextView appid = (TextView) vi.findViewById(R.id.hidenappoinment);
final ImageView img = (ImageView) vi.findViewById(R.id.list_image2);
HashMap<String, String> song = new HashMap<String, String>();
song =data.get(position);
//firstname.setText(song.get(MainActivity.TAG_PROP_FNAME));
//lastname.setText(song.get(MainActivity.TAG_PROP_LNAME));
startTime.setText(song.get(MainActivity.TAG_STIME));
endTime.setText(song.get(MainActivity.TAG_ETIME));
date.setText(song.get(MainActivity.TAG_DATE));
uid.setText(song.get(ShortList.TAG_UID));
appid.setText(song.get(ShortList.TAG_APOINMENTID));
//imageLoader.DisplayImage(song.get(CustomizedListView.KEY_THUMB_URL), img);
vi.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//String getFname = firstname.getText().toString();
Toast.makeText(parent.getContext(), "view clicked: " , Toast.LENGTH_SHORT).show();
//get the id of the view
//check the id of the request
//call the web service acording to the id
AlertDialog.Builder alertbuild = new AlertDialog.Builder(activity);
alertbuild.setMessage("Everything else will be Considerd as Rejected! Are You Sure ?");
alertbuild.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, int which) {
// TODO Auto-generated method stub
//Toast.makeText(mContext, "Yes ", Toast.LENGTH_LONG).show();
final String getStime = startTime.getText().toString();
final String getEtime = endTime.getText().toString();
final String getDate = date.getText().toString();
final String getUid = uid.getText().toString();
final String getapid = appid.getText().toString();
final ProgressDialog ringProgressDialog = ProgressDialog.show(activity, "Please wait ...", "Request is in Progress ...", true);
ringProgressDialog.setCancelable(false);
new Thread(new Runnable() {
@Override
public void run() {
try {
// Here you should write your time consuming task...
// Let the progress ring for 10 seconds...
// ShortList sendandget = new ShortList();
// String resp = sendandget.sendDataAndGetResponce(getDate, getStime, getEtime,getUid,getapid);
// if(resp.equalsIgnoreCase("true")){
// }
Thread.sleep(10000);
} catch (Exception e) {
e.printStackTrace();
}
ringProgressDialog.dismiss();
Toast.makeText(mContext, "Your Request Accepted", Toast.LENGTH_LONG).show();
dialog.dismiss();
}
}).start();
// ArrayList<HashMap<String, String>> rfejected = getRejected.getRejectedList(getDate, getStime, getEtime,getUid,getapid);
//ArrayList<HashMap<String, String>> accept = getRejected.getAccept(getDate, getStime, getEtime,getUid,getapid);
// sendaceptedAndReject(accept,getUid,rfejected,getapid);
}
})
.setNegativeButton("NO", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Toast.makeText(mContext, "No ", Toast.LENGTH_LONG).show();
}
});
alertbuild.show();
}
});
return vi;
}
我试图发布一条 toast 消息以了解天气是否正常工作。进度对话框正在显示,但在我等待它的时间之后,它就被解雇了,没有显示我的 toast 消息。
请有人帮助我
我尝试过使用异步任务
这是我的编码..我没有做任何复杂的事情..只是想让 C 它工作与否..但是 OnPreExecute() 它没有显示 progressDialog :(
public class ShowResponce extends AsyncTask<String, Void, String>{
private ProgressDialog pDialog;
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
pDialog = new ProgressDialog(activity);
pDialog.setMessage("Getting Data ...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
@Override
protected String doInBackground(String... arg0) {
// TODO Auto-generated method stub
//ShortList sendandget = new ShortList();
//String resp = sendandget.sendDataAndGetResponce(getDate, getStime, getEtime,getUid,getapid);
String x="a";
return x;
}
@Override
protected void onPostExecute(String x) {
// TODO Auto-generated method stub
pDialog.dismiss();
Toast.makeText(mContext, x, Toast.LENGTH_LONG).show();
}
}
【问题讨论】:
-
哪种吐司不起作用?
-
这个:Toast.makeText(mContext, "Your Request Accepted", Toast.LENGTH_LONG).show();
-
使用AsyncTask调用web-service
标签: android multithreading dialog