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

  • Home
  • SEARCH
  • 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 6069567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:50:11+00:00 2026-05-23T09:50:11+00:00

I used the HelloTabWidget from here (http://developer.android.com/resources/tutorials/views/hello-tabwidget.html) as a starting point. Now I edited

  • 0

I used the HelloTabWidget from here (http://developer.android.com/resources/tutorials/views/hello-tabwidget.html) as a starting point.

Now I edited the onCreate for the first Tab:

// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("tab0").setIndicator("Tab0", res.getDrawable(R.drawable.ic_tab_artists));
spec.setContent(new MyTabContentFactory(this, R.layout.tab0));
tabHost.addTab(spec);

MyTabContentFactory:

public class MyTabContentFactory implements TabContentFactory {

    private Activity parent = null;
    private int layout = -1;

    public MyTabContentFactory(Activity parent, int layout) {
        this.parent = parent;
        this.layout = layout;
    }


    @Override
    public View createTabContent(String tag) {
        View inflatedView = View.inflate(parent, layout, null);//using parent.getApplicationContext() threw a android.view.WindowManager$BadTokenException when clicking ob the Spinner.
        //initialize spinner
        CharSequence array[] = new CharSequence[4];
        for (int i = 0; i < array.length; i++) {
            array[i] = "Element "+i;
        }
        ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(parent, android.R.layout.simple_spinner_item, array);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

        View view = parent.findViewById(layout);
        if(view != null) {
            ArrayList<View> touchables = view.getTouchables();
            for (View b : touchables) {
                if (b instanceof Spinner) {
                    ((Spinner) b).setAdapter(adapter);
                }
            }
        }

        return inflatedView;
    }
}

tab0.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <Spinner
        android:id="@+id/entry1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:prompt="@string/brand_prompt"
        />
</RelativeLayout>

MyTabContentFactory should initialize the Spinner, but view in createTabContent is always null. Why is that so? How can I find the Spinner in order to initialize it?

  • 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-23T09:50:12+00:00Added an answer on May 23, 2026 at 9:50 am

    This line

     View view = parent.findViewById(layout);
    

    means nothing, I see what your trying to do, but it just doesn’t work like that. You can’t get views off your activity you have to reference the inflated XML view.

    I think what your trying to do is this:

     ArrayList<View> touchables = inflatedView.getTouchables();
            for (View b : touchables) {
                if (b instanceof Spinner) {
                    ((Spinner) b).setAdapter(adapter);
                }
            }
    

    but tbh you don’t even need to do that, you should do this:

     Spinner spinner = (Spinner) inflatedView.findViewById(R.id.entry1);
     spinner.setAdapter(adapter);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Used http://www.ilbcfreeware.org/software.html - I only get static from the files that ilbc_test.exe creates. Does
I used http://www.youtube.com/get_video?video_id=ID&t=SIGNATURE&fmt=18 replaced ID and SIGNATURE with the proper values. But I don't
I used this menu as a template for my own : http://ago.tanfa.co.uk/css/examples/menu/hs7.html I used
When used like this: import static com.showboy.Myclass; public class Anotherclass{} what's the difference between
I used to be able to do the following in Preview 3 <%=Html.BuildUrlFromExpression<AController>(c =>
You used to be able to do: resources :posts, :singular => true But I
I used this code to select top 5 users from jQuery grid on button
I used Eclipse with the Android SDK to develop the original application. I ask
I've always used Xcode in the past so now I'm trying to learn Android
Used code first and everything appears to work apart from the below which also

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.