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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:42:03+00:00 2026-06-01T09:42:03+00:00

In my app, users can tap on image thumbnails to see a full size

  • 0

In my app, users can tap on image thumbnails to see a full size version. When the thumbnail is tapped a bunch of new views are created in code (i.e. no XML), appended at the end of the view hierarchy and some scaling and rotating transitions happen, then the full size, high res version of the image is displayed. Tapping on the full size image reverses the transitions and removes the new views from the view hierarchy.

I want users to also be able to press the BACK key to reverse the image transitions. However, I can’t seem to catch the KeyEvent. This is what I’m trying at the moment:

        // Set a click listener on the image to reverse everything
        frameView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0)
            {
                zoomOut(); // This works fine
            }
        });

        // Set the focus onto the frame and then set a key listener to catch the back buttons
        frameView.setFocusable(true);
        frameView.setFocusableInTouchMode(true);
        frameView.requestFocus();
        frameView.setOnKeyListener(new OnKeyListener() {

            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event)
            {
                // The code never even gets here !!!
                if(keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0)
                {
                    zoomOut();
                    return true;
                }
                return false;
            }
        });

EDIT : I’ve had a couple of answers of people providing code snippets to be used within a class that extends Activity. This code I’ve copied above exists in a class that is instantiated in multiple activities; my goal is to have the code that listens for and catches the BACK key event in the one place (like the OnClickListener()) instead of having to have it in every activity (and create long, unwieldy references from each activity to the zoomed object).

  • 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-01T09:42:04+00:00Added an answer on June 1, 2026 at 9:42 am
    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
    // TODO Auto-generated method stub
    if(keyCode == KeyEvent.KEYCODE_BACK)
    {
    //Your logic or stuff
    return true;
    }
    else
    return super.onKeyUp(keyCode, event);
    }
    

    Use the above overide method to handle Back key press event

    In these scenario use as below
    1) create a activity as below::

    /**
     * Top Activity that extends all Activity
     */
    package com.com.com;//change your package name
    
    import android.app.Activity;
    import android.view.KeyEvent;
    
    
    public class TopActivity extends Activity {
        protected BaseActivity _activity;
    
    
        @Override
        public boolean onKeyDown(int keyCode, KeyEvent event) {
            // TODO Auto-generated method stub
            if(keyCode == KeyEvent.KEYCODE_BACK){
                //your stuff if you wanna to have anything
                return true;
            }
            else
                return super.onKeyDown(keyCode, event);
        }
        @Override
        public boolean onKeyUp(int keyCode, KeyEvent event) {
            // TODO Auto-generated method stub
            if(keyCode == KeyEvent.KEYCODE_BACK)
            {
                //your stuff if you wanna to have anything
                return true;
            }
            else
                return super.onKeyUp(keyCode, event);
        }
    
    }
    

    2) Now in your code your every activity extends Acitivity, so change it such that it extend TopActivity like below::

    public class YourActivity extends TopActivity {
    

    //Your normal code for each activity…
    }

    thats it… Try it now

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

Sidebar

Related Questions

I have an app where users can sign up with Facebook, in which case
I'm writing an Android app where users can upload video to Youtube. I'd like
I have a wizard in my app where users can go back and forward
I have a vector drawing app where users can draw lines using multiple quadratic
We have an HTML5 drawing app where users can draw lines using a pencil
I have a form in my django app where users can upload files. How
I have an app in which users can follow law firms I have 3
I am developing a BlackBerry app in which users can purchase virtual goods (such
I'm working on a Rails app that existing users can invite additional members to
I have a web app where users can upload files. The files are physically

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.