Progress dialog dismiss manually

Put your problem here if it does not fit any of the other categories.

Progress dialog dismiss manually

Postby devdattac » Wed Jun 23, 2010 1:35 pm

Hi All,

I am displaying progress dialog when I want to download some data from server . I want to dismiss progress dialog manually on the key press event such as key event of BACK key of device. How should I done this ?

Please help me ASAP........

Thanx
devdattac
Junior Developer
Junior Developer
 
Posts: 13
Joined: Thu Jan 15, 2009 2:14 pm
Location: Pune

Top

Re: Progress dialog dismiss manually

Postby HaitiBoy » Wed Jun 23, 2010 6:03 pm

You just have to set your ProgressDialog cancelable. And it will disappear when you click "Back" button.
But you can also dismiss it by calling: dialog.dismiss();

Here is some code:
Code: Select all
package com.example;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;

public class Dialog extends Activity {

  private LinearLayout main_;
  private Button showDialog_;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    main_ = new LinearLayout(this);

    showDialog_ = new Button(this);
    showDialog_.setText("Show dialog");
    showDialog_.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(View v) {
        // Creating a dialog
        ProgressDialog dialog = new ProgressDialog(Dialog.this);
        dialog.setMessage("Dialog");
        // This is what you need(setCancelable):
        dialog.setCancelable(true);
        dialog.show();
      }

    });

    main_.addView(showDialog_);
    setContentView(main_);
  }
}
HaitiBoy
Freshman
Freshman
 
Posts: 6
Joined: Fri Jun 18, 2010 6:35 pm
Location: Houghton, Michigan

Re: Progress dialog dismiss manually

Postby devdattac » Thu Jun 24, 2010 5:30 am

Thanks for the reply HaitiBoy.......

I am using ProgressDialog.show(...) method to invoke progress dialog during Async operation. But when Progress dialog is visible it failed to receive key events. What will be the solution for it ?
devdattac
Junior Developer
Junior Developer
 
Posts: 13
Joined: Thu Jan 15, 2009 2:14 pm
Location: Pune

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 18 guests