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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:37:16+00:00 2026-06-11T21:37:16+00:00

I’m creating a Spinner dynamically like the code below: private void createCoordinationSpinner() { TextView

  • 0

I’m creating a Spinner dynamically like the code below:

private void createCoordinationSpinner() {
    TextView tvwCoordination = new TextView(this);
    this.spinnerCoordination = new Spinner(this);

    //Some code to setup textview... 

    LinearLayout.LayoutParams paramsSpinnerCoordination = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
    paramsSpinnerCoordination.setMargins(10, 0, 10, 0);

    this.spinnerCoordination.setLayoutParams(paramsSpinnerCoordination);
    this.spinnerCoordination.setBackgroundResource(R.drawable.rounded_border);
    this.spinnerCoordination.setPrompt("Coordination");
    this.spinnerCoordination.setOnItemSelectedListener(spinnerItemClickListener);

    //Adding both views to an existing LinearLayout, that is possible to have another views, instead of spinner
    linearSchoolCoordination.addView(tvwCoordination, 0);
    linearSchoolCoordination.addView(spinnerCoordination, 1);
    linearSchoolCoordination.setGravity(Gravity.BOTTOM);
}

//Thats the line that sets the adapter:
adapterCoordination = new ItemSpinnerAdapter(context, R.layout.coordinationspinnerlayout, arrayCoordination);

rounded_border.xml:

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="@color/gray_dialog" /> 
    <padding android:left="8dp" 
        android:top="8dp" 
        android:right="8dp" 
        android:bottom="8dp" /> 
    <corners android:radius="20dp" /> 
</shape>

coordinationspinnerlayout.xml:

<LinearLayout   android:orientation="vertical" 
                android:background="@color/transparent2" 
                android:layout_height="fill_parent" 
                android:layout_width="fill_parent" 
                xmlns:android="http://schemas.android.com/apk/res/android"> 

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@color/transparent2"
        android:orientation="vertical" >

        <LinearLayout
            android:id="@+id/linearLayout1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@color/transparent2"
            android:gravity="center_vertical" >

            <ImageView  android:layout_height="wrap_content" 
                        android:layout_width="wrap_content" 
                        android:id="@+id/imageSpinnerItem" 
                        android:src="@drawable/itemlistviewicon_nochildren" 
                        android:layout_marginTop="5dp" 
                        android:layout_marginLeft="8dp" 
                        android:layout_marginBottom="5dp"/> 

            <TextView   android:layout_height="wrap_content" 
                        android:layout_width="wrap_content" 
                        android:id="@+id/tvwSpinnerCoordination" 
                        android:layout_marginLeft="10dp" 
                        android:textSize="16dip" 
                        android:textColor="@color/black" 
                        android:text="TextView" 
                        android:layout_weight="1"/> 

            <ImageView  android:layout_height="20dp" 
                        android:layout_width="20dp" 
                        android:id="@+id/imageSpinnerDownArrow" 
                        android:src="@drawable/spinnerdownarrow" 
                        android:layout_marginTop="5dp" 
                        android:layout_marginBottom="5dp" 
                        android:layout_marginRight="10dp"/> 
        </LinearLayout> 

        <View   android:background="@color/silver" 
                android:layout_height="1dp" 
                android:layout_width="fill_parent" 
                android:id="@+id/linearSpinnerSeparator"/> 

    </LinearLayout> 

</LinearLayout>

And finally, the adapter, ItemSpinnerAdapter.java:

public class ItemSpinnerAdapter extends ArrayAdapter<CoordinationData> 
{
    private int tvwID;
    private List<CoordinationData> coordinationList;

    public ItemSpinnerAdapter(Context context, int textViewResourceId, List<CoordinationData> coordinationList) 
    {
        super(context, textViewResourceId, coordinationList);

        this.tvwID = textViewResourceId;
        this.coordinationList = coordinationList;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) 
    {
        ViewHolder holder;
        View view = convertView;

        if (view == null) 
        {
           LayoutInflater layInf = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
           view = layInf.inflate(tvwID, null);

           holder = new ViewHolder();
           holder.tvwDescription = (TextView) view.findViewById(R.id.tvwSpinnerCoordination);
           holder.description = coordinationList.get(position).getCoordinationName();

           view.findViewById(R.id.linearSpinnerSeparator).setVisibility(View.GONE);
           view.setTag(holder);

        } 
        else 
        {
            holder = (ViewHolder) view.getTag();
            holder.description = coordinationList.get(position).getCoordinationName();
        }

        if (holder.tvwDescription != null) 
            holder.tvwDescription.setText(holder.description);

        return view;
    }

    @Override
    public View getDropDownView(int position, View convertView, ViewGroup parent) 
    {
        ViewHolder holder;
        View view = convertView;

        if (view == null) 
        {
            LayoutInflater layInf = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = layInf.inflate(tvwID, null);

            holder = new ViewHolder();
            holder.tvwDescription = (TextView) view.findViewById(R.id.tvwSpinnerCoordination);
            holder.tvwDescription.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
            holder.description = coordinationList.get(position).getCoordinationName();

            view.findViewById(R.id.imageSpinnerDownArrow).setVisibility(View.GONE);
            view.setTag(holder);

        } 
        else 
        {
            holder = (ViewHolder) view.getTag();
            holder.description = coordinationList.get(position).getCoordinationName();
        }

        if (holder.tvwDescription != null) 
            holder.tvwDescription.setText(holder.description);

    return view;
}

public class ViewHolder 
{
    TextView tvwDescription;
    String description;
}
}

adding it to a LinearLayout that already exists in my activity’s XML layout file.
Along with my CustomSpinnerAdapter, it works pretty well.
But I still need to change some properties and I’m stucked…
Since my app is using blue texts and backgrounds, I’d like to set the selection of a spinner item highlight color. Its default is orange.

Since I’m developing for API 10, I’m using limited Spinner methods.

Any suggestions?
Thanks in advance!

EDIT: is that possible to change prompt header background color?

EDIT2: adding further code.

  • 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-11T21:37:17+00:00Added an answer on June 11, 2026 at 9:37 pm

    After long time searching for a solution,

    I found out that I can’t set style or change its selection color dynamically ’cause of the API version that I’m developing.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words

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.