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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:29:49+00:00 2026-05-23T15:29:49+00:00

I have found that when using a d-pad or trackball to navigate in my

  • 0

I have found that when using a d-pad or trackball to navigate in my app if you move to the right and the list view looses focus, when the list view regains focus, a different child is given focus than last had focus. I tried to use onFocusChange(…) to save which child had focus but it looks like this isn’t called until after the focus is lost so I can never grab which child last had focus. Is there a way to grab who had focus so I can then call requestFocus() on the child once the list view grabs focus again?

Unfortunately I cannot use a handler because this isn’t a much used feature and I don’t want to sacrifice the performance for a smaller feature.

Here is the code I had that didn’t work (focusedView was always null no matter what):

mainListView.setOnFocusChangeListener(new OnFocusChangeListener() {

        public void onFocusChange(View v, boolean hasFocus) {
            if(focusedView == null ) { Log.i("focus", "focusedView == null"); }
            if(hasFocus && focusedView != null) {
                Log.i("focus", "Focus has been Recieved.............");
                focusedView.requestFocus();
            } else {
                // Focus has been lost so save the id of what the user had selected
                Log.i("focus", "Focus has been Lost.............");
                focusedView = mainListView.findFocus();
            }
        }
    });

Thanks!

  • 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-05-23T15:29:49+00:00Added an answer on May 23, 2026 at 3:29 pm

    I think you are spot on with your own answer, bascially since the focus listener is called after its lost focus, no child will be in focus and therefore .findFocus() will return null.

    I recon you best bet is to extend the ListView class, and override the onFocusChanged method. Basically do what you are doing, but do it inthere when gainFocus is true.

    @Override
    protected void onFocusChanged (boolean gainFocus, 
         int direction, Rect previouslyFocusedRect) {
         if(gainFocus)
             focusedView = mainListView.findFocus();
    
    }
    

    This one

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

Sidebar

Related Questions

I have found that while using the <meta name=apple-mobile-web-app-capable content=yes /> tag in iOS
I have found that creating a zip file using the Zip task provided by
The only reliable method that I a have found for using a script to
I have found that People claim that using all readonly fields in a class
I have found that when using Subclipse to edit conflicts, all my syntax color
I am using the jquery countdown timer here http://www.littlewebthings.com/projects/countdown/ and I have found that
I have started using Code Contracts and have found that it makes it difficult
I'm using VS2008 (version 9.0.30729.1 SP) and have found that outlining regularly stops working.
Using MVC3 I have found that setting a SelectList's selected value correctly renders the
Using Firebug I have found that the Dynatree plugin changes the following code: <li

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.