Get the time when you show the m_ProgressDialog and then instead of dismissing the m_ProgressDialog in your "If" statement calculate how long it has been visible and post a delayed message to a handler so that it will show for the time you want, and then raise your toast and start your new activity from the handler after dismissing the Dialog.



On 12/06/2010 9:07 AM, pawan nimje wrote:
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

--
Sincerely,

Brad Gies
-----------------------------------------------------------------------
Bistro Bot - Bistro Blurb
http://www.bgies.com
http://www.bistroblurb.com
http://www.bistrobot.com
-----------------------------------------------------------------------

Never doubt that a small group of thoughtful, committed people can
change the world. Indeed. It is the only thing that ever has - Margaret Mead

--
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

Reply via email to