Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8065441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:40:06+00:00 2026-06-05T11:40:06+00:00

I wrtie a small program to test ProgressDialog in Android. DialogInterface.OnKeyListener dialogKey = new

  • 0

I wrtie a small program to test ProgressDialog in Android.

    DialogInterface.OnKeyListener dialogKey = new DialogInterface.OnKeyListener() {
        public boolean onKey(DialogInterface arg0, int arg1, KeyEvent arg2) {
            switch(arg1) {
            case KeyEvent.KEYCODE_VOLUME_DOWN:
                Log.i("Spinner Key", "Key Volume Down");
                            Log.i("Spinner Key", "" + arg0.toString());
                return true;
            case KeyEvent.KEYCODE_VOLUME_UP:    
                Log.i("Spinner Key", "Key Volume Up"); 
                            Log.i("Spinner Key", "" + arg0.toString());
                return true;                
            default:
                    break;
            }
            return true;
        }
    };            


        this.mypDialog = new ProgressDialog(SensorDefenceActivity.this);             
        this.mypDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        this.mypDialog.setTitle("Count");
        this.mypDialog.setIndeterminate(false);
        this.mypDialog.setMessage(this.start + "");
        this.mypDialog.setCancelable(false);
        this.mypDialog.setCanceledOnTouchOutside(false);
        this.mypDialog.setButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int i)
            {
                dialog.cancel();
            }
        });

        mypDialog.setOnKeyListener(dialogKey);
        mypDialog.show();   
        mypDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD); 

When the dialog shows, I press one of the volume keys. But I get the same key press notification in logcat twice!

06-08 17:54:07.130: I/Spinner Key(11636): Key Volume Up
06-08 17:54:07.130: I/Spinner Key(11636): android.app.ProgressDialog@402bdd78
06-08 17:54:07.260: I/Spinner Key(11636): Key Volume Up
06-08 17:54:07.260: I/Spinner Key(11636): android.app.ProgressDialog@402bdd78
06-08 17:54:11.320: I/Spinner Key(11636): Key Volume Down
06-08 17:54:11.320: I/Spinner Key(11636): android.app.ProgressDialog@402bdd78
06-08 17:54:11.530: I/Spinner Key(11636): Key Volume Down
06-08 17:54:11.530: I/Spinner Key(11636): android.app.ProgressDialog@402bdd78

I promise that the press time is very short so that it can’t trigger the same key press message twice.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T11:40:07+00:00Added an answer on June 5, 2026 at 11:40 am

    onKey is executed for Both KeyEvent.ACTION_UP and KeyEvent.ACTION_DOWN. (ie arg2)

    Execute your code for just one of them. I think ACTION_DOWN should be the one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a small test program that gives the following xml file as
With a small test program (compiled with mingw on Linux), I noticed that one
I am currently making a small test program for simple file checking. The program
I need to write a small program which to test whether a line (position
Hey there. I'm trying to write a small program that will read the four
I wrote a small program using a custom indexOf function but wanted to dismiss
I wrote a small program that uses Mechanize to traverse a site. I want
I have a small program with many widgets like checkboxes, textctrls, statictexts,... The values
I have a program that opens a large binary file, appends a small amount
I want to write some small program. It will run on my computer(laptop) with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.