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 8373187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:36:59+00:00 2026-06-09T14:36:59+00:00

I was previously extending the Dialog class for my dialogs and I had to

  • 0

I was previously extending the Dialog class for my dialogs and I had to use the following code segment in my dialogs so that they would not be dismissed when the phone’s search key was pressed:

setOnKeyListener(new OnKeyListener()
{
  public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event)
  {
    if (keyCode == KeyEvent.KEYCODE_SEARCH)
      return true; // pretend we've processed it
    else
      return false; // pass on to be processed as normal
  }
});

I am now using the DialogFragment class for my dialogs. Unfortunately DialogFragment has the same problem as Dialog in that dialogs are dismissed when the phone’s search key is pressed (regardless of the dialog’s cancelable state). Doubly problematic is that DialogFragment does not have a setOnKeyListener method so the above code segment no longer applies.

Anyone know how I can get my dialogs (when showing) to ignore search key presses?

Note: I tried adding the above code segment to my activity’s onKeyUp
method but unfortunately my activity’s onKeyUp method is not called
if a DialogFragment instance is showing. Instead, irritatingly, the
DialogFragment instance is dismissed.

  • 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-09T14:37:01+00:00Added an answer on June 9, 2026 at 2:37 pm

    Try this.
    Inside your DialogFragment.Onresume

     getDialog().setOnKeyListener(new OnKeyListener()
     {
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event){
        if (keyCode == KeyEvent.KEYCODE_SEARCH)
          return true; // pretend we've processed it
        else
          return false; // pass on to be processed as normal
      }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Previously, I have an app that uses core data. I use same store url
I've got an JSP tag that I would like to use in my JSF/Seam
Previously I'd worked on a flash application that would be embedded into a webpage
I would like to use Tree Apache Wicket to implement the following opeation: Top
Previously in ext 3.0 we had Tree Panel built from XML response. For that
Previously, I had my LegNo enums defined simply as: NO_LEG, LEG_ONE, LEG_TWO and by
I'm using mvc approach and extending the pandora example. I would like to add
I have a class extending JFrame which contains group of radioButtons and a submit
I encountered a PHP class written by a previous employee that is defined like
I have a test class extending junit.framework.TestCase with several test methods.Each method opens a

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.