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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:53:13+00:00 2026-05-27T17:53:13+00:00

In my Android application I create the layout programatically (ie an xml layout file

  • 0

In my Android application I create the layout programatically (ie an xml layout file not used for creating the component layout), in this case how can I create a spinner component programatically? Especially the setAdapter portion of spinner component, Is it possible create an ArrayAdapter with out using an XML layout reference like ‘android.R.layout.spinner_item’?

          Spinner sp_gender = new Spinner(this);
          ArrayList<String> spinnerArray = new ArrayList<String>(); 

         ArrayAdapter spinnerArrayAdapter = new ArrayAdapter(this,
               android.R.layout.spinner_item, new String[] {   
                      "Male", 
                      "Female"                
                     });

         sp_gender.setAdapter(spinnerArrayAdapter); 

         ll_main.addView(sp_gender);

In the above code I want to remove the xml file reference portion ‘android.R.layout.spinner_item’ because I create the layout completely in the activity class.

  • 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-27T17:53:13+00:00Added an answer on May 27, 2026 at 5:53 pm

    No its not possible. Because ArrayAdapter has no default constructor. also u need to specify the structure of the view and also on which it should draw the view thats why arrayadapter takes layout id and context as one of its parameter

    ArrayAdapter(Context context, int textViewResourceId) is the constructor of ArrayAdapter with least parameter.

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

Sidebar

Related Questions

I'm trying to create a TabActivity for my android application. When my layout XML
I'm trying create a scaling layout for an Android application. The whole screen should
I want to write application where I create layout in the code (without xml-layout
I'm working on a Android application that involves a lot of XML layout files.
I am struggling in how to create this layout [ImageShack Link] for my android
Hey I want to create a layout like this for my application. Of course
My Android application can't use XML buttons, because the size and label of the
I am currently trying to create an Android application that loops Audio from the
I am trying to create a simple Android application that has a ActivityList of
If I create an application for Android, how do you package extra items in

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.