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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:16:59+00:00 2026-05-22T16:16:59+00:00

I have a TabWidget nested within a HorizontalScrollView . I am programmatically setting the

  • 0

I have a TabWidget nested within a HorizontalScrollView. I am programmatically setting the active/current tab (which I have no problem doing). My problem is, the TabWidget is not scrolling to show thenewly active tab.

Example – I have 9 tabs, only 3 are shown at any given time (so think 3 ‘pages’ of tabs). I am on tab 1 (page 1). I programmatically set the current tab to tab 8 (page 3). The tab content switches properly (ie, I now see the contents of tab 8), however, the tabs up at the top still show tabs 1, 2, and 3. If I manually scroll over to the right, I will see tab 8 (properly highlighted). I want to automatically scroll the TabWidget so that the currently active tab is shown.

Any ideas?

EDIT example source:

 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        String tag;

        /* logic to populate tag from intent*/

        /* reason for this is because I know the tag of the tab I need, 
           not the index num. of tab */
        getTabHost().setCurrentTabByTag(tag);
        int i = getTabHost().getCurrentTab();

        getTabWidget().setCurrentTab(i);
        getTabWidget().focusCurrentTab(i);
    }
  • 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-22T16:16:59+00:00Added an answer on May 22, 2026 at 4:16 pm

    You must both focusCurrentTab(int i) and setCurrentTab(int i). focusCurrentTab(i) will focus the UI of the TabWidget to the ith tab (what you want), and, as you already know, setCurrentTab(i) will focus the actual content of the ith tab in the main View.

    For reference: http://developer.android.com/reference/android/widget/TabWidget.html#focusCurrentTab(int)

    EDIT:

    My answer was incorrect. This is the correct one (that the the poster found out themself):

    It turns out that the TabWidget views had focusableInTouchMode set to false. As per View.java documentation:

    A view will not actually take focus if it is not focusable ({@link #isFocusable}
    returns false), or if it is focusable and it is not focusable in touch mode
    ({@link #isFocusableInTouchMode}) while the device is in touch mode.
    To correct the problem I iterated over the TabWidget views and set them focusable in touch mode:

    for (int i = 0; i < count; i++) {
        getTabWidget().getChildAt(i).setFocusableInTouchMode(true);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to set the TabWidget height and have the tab labels adjust?
I have a TabActivity with a tab, which shows a list. I'd like to
In android I have an TabActivity (A) in which I create a single tab
I have a program that is a TabWidget that calls different activities. The problem
I have a TabHost, where the tab content is a ViewFlipper: <TabHost> <LinearLayout> <TabWidget
I have an Android tab layout with three tabs, one of which has a
I am following this tutorial https://developer.android.com/guide/tutorials/views/hello-tabwidget.html and have completed it. Now I would actually
Have just started using Visual Studio Professional's built-in unit testing features, which as I
When a TabWidget is using intents to designate the target Activity for each tab,
As per the android developer docs for creating tab UI you need to have

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.