im developing a app for showing data which is got from a web service to a list view.actually according to my application: when user clicks an item from a list view it should be asked some message with a dialog box. when user press "yes" there is an web service call process happening. so.. i want to show a progress dialog until the web service call process done(the method which is use to call web service returns a string message.i want to show that message after this progress dialog dismissed).
i am writing these code inside the getview method of my adapter class.
this is my code
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;
}
i have tried to put a toast message to know weather it is working or not.the progressdialog is showing, but after the time which i gave to wait its just dismissed without showing my toast message.
please someone help me
i have tried using assync task
this is my coding..i didnt do any complex things.. just want to C it working or not.. but OnPreExecute() it is not shown the 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();
}
}