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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:46:01+00:00 2026-06-15T13:46:01+00:00

I have class, which extends LinearLayout , in it there are Buttons and a

  • 0

I have class, which extends LinearLayout, in it there are Buttons and a Spinner.

This Object gets included via my layout XML file:

<com.ics.spinn.ComboBox android:id="@+id/myautocombo"
  android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:completionThreshold="1"
android:entries="@array/suppliers" />
/>

The array suppliers is defined in strings.xml.

If this component now wouldn’t be com.ics.spinn.ComboBox, but a Spinner, Android would
auto-populate the “android:entries” to the Spinner adapter.

I’d like my component com.ics.spinn.ComboBox to behave the same way:
to be able to access the array defined via the xml file, so I can
supply it to the Spinner inside my component, via:

    ArrayAdapter<String> a = new ArrayAdapter<String>(this.getContext(),android.R.layout.simple_spinner_dropdown_item, ARRAYINSIDEMYXML);
    s.setAdapter(a);

I now I could access the array defined in strings.xml DIRECTLY via getResources().getStringArray(R.array.suppliers)
but my code shouldn’t know of the name “suppliers”, since it shall be supplied via android:entries…

This + the entries in xml in João Melo solution WORK:

        public ComboBox(Context context, AttributeSet attrs) {
        super(context, attrs);

          TypedArray b = context.obtainStyledAttributes(attrs,
                    R.styleable.ComboBox, 0, 0);

            CharSequence[] entries = b.getTextArray(R.styleable.ComboBox_myEntries);
            if (entries != null) {
                ArrayAdapter<CharSequence> adapter =
                        new ArrayAdapter<CharSequence>(context,
                                android.R.layout.simple_spinner_item, entries);
                adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                s.setAdapter(adapter);
            }
}
  • 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-15T13:46:02+00:00Added an answer on June 15, 2026 at 1:46 pm

    I don’t know if it’s possible to do that with android:entries attribute unless your component extends Spinner, but I’m only guessing.

    You can achieve that creating your own custom attribute in attrs.xml

    <declare-styleable name="ComboBox">
        <attr name="myEntries" format="reference"></attr>
    </declare-styleable>
    

    Then you can access this reference (int) inside your component and set the ArrayAdapter into your spinner.

    TypedArray customAttrs = context.obtainStyledAttributes(attrs, R.styleable.ComboBox);
        for (int i = 0; i < customAttrs.length(); i++) {
            int attrValue = customAttrs.getIndex(i);
            switch (attrValue) {
                case R.styleable.ComboBox_myEntries:
                    mArrayId = customAttrs.getResourceId(attrValue, 0);
                    ArrayAdapter<String> a = new ArrayAdapter<String>(this.getContext(),android.R.layout.simple_spinner_dropdown_item, mArrayId);
                    s.setAdapter(a);
                    break;
            }
        }
    

    On your layout, add this line xmlns:app="http://schemas.android.com/apk/res/yourPackageName" below xmlns:android="http://schemas.android.com/apk/res/android" in the root view:

    Then you can instantiate your component and custom attrs via xml:

    <com.ics.spinn.ComboBox android:id="@+id/myautocombo"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:completionThreshold="1"
    app:myEntries="@array/suppliers" />
    />
    

    Don’t know if this answer is exactly what you’re looking for but it would behave just like android:entries. Hope it helps.

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

Sidebar

Related Questions

I have a CustomButton class (extends LinearLayout ) where I inflate a layout which
Hi Experts: I have a class which extends JPanel now ShapePanel (Sp) this gets
I have class A which extends the Activity class. This class is in package
So I have this class which extends an activity. But I want to draw
I have created a class which extends Gallery. There is no onCreate() method in
I am trying to create downloading progress. I have my class which extends AsyncTask:
I have a actionSave class which extends AbstractAction.I use it for save button. somewhere
I have created a class which extends View class. public class SplashScreen extends View
I have a class XYZ which extends Thread and it is also a singleton
i have a class User which extends Ebean Model. And i defined a dbfile

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.