Below is the code for posting data on a server ...
my problem is i want to show a progress dialog when i click on submit button
....and dismiss it when data is posted ...
i have written code for that .. but the thing is the progress dialog comes
and goes ... and its hardly noticeable ..
i hope u have understood my prob .... so plz suggest solution ...
_________________________________________________________________________________________________
final Button btnSubmit = (Button) findViewById(R.id.submitButton);
btnSubmit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
btnSubmit.setEnabled(false);
etPersonName = (EditText) findViewById(R.id.byEditText);
etPostText = (EditText) findViewById(R.id.postEditText);
b = true;
try {
String personName = new String();
personName = etPersonName.getText().toString();
String postStr = new String();
postStr = etPostText.getText().toString();
if(personName.length() == 0 || postStr.length() == 0)
{
Toast.makeText(getApplicationContext(), "Message
and/or Sender's Name cannot be Blank." , Toast.LENGTH_SHORT).show();
btnSubmit.setEnabled(true);
}
else
{
btnSubmit.setEnabled(false);
* m_ProgressDialog =
ProgressDialog.show(LeaveMessage.this, "Please wait...", "Saving Post ...",
true);*
String msgStr = personName + "<~>" + postStr;
String encryptStr = msgStr + "&" +
Constants.POST_KEY;
String android_id =
Secure.getString(cntxt.getContentResolver(), Secure.ANDROID_ID);
String sha1Msg = SimpleSHA1.SHA1(encryptStr);
Constants.LeaveURL = Constants.BasicLeaveURL;
Constants.LeaveURL += "?tp=new&";
Constants.LeaveURL += "message=" + msgStr + "&";
Constants.LeaveURL += "key=" + sha1Msg + "&";
if (android_id == null)
{
Constants.LeaveURL += "DeviceId=" + "12312" +
"&";
}
else
{
Constants.LeaveURL += "DeviceId=" + android_id +
"&";
}
Constants.LeaveURL += "cCode=" +
Constants.CountryCode;
System.out.println(Constants.LeaveURL);
URL url = new URL(Constants.LeaveURL);
HttpURLConnection conn =
(HttpURLConnection)url.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setRequestMethod("POST");
/* setRequestProperty */
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("Charset", "UTF-8");
conn.setRequestProperty("Content-Type",
"multipart/form-data");
DataOutputStream ds = new
DataOutputStream(conn.getOutputStream());
if(Constants.takePhoto!=null)
{
ByteArrayOutputStream baos = new
ByteArrayOutputStream();
Constants.takePhoto.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] data = baos.toByteArray();
ds.write(data);
}
Constants.takePhoto=null;
ds.flush();
ds.close();
* //m_ProgressDialog.dismiss();*
if(conn.getResponseCode() !=
HttpURLConnection.HTTP_OK){
Toast.makeText(getBaseContext(),
conn.getResponseMessage(), Toast.LENGTH_LONG);
}
else{
* m_ProgressDialog.dismiss();*
Toast.makeText(getBaseContext(), "Message
Posted!!", Toast.LENGTH_LONG);
Intent i = new Intent(getApplicationContext(),
ReadMessages.class);
startActivity(i);
}
}
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en