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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:09:10+00:00 2026-06-17T13:09:10+00:00

I trying to make a custom Spinner containing Id and Title. This Spinner displays

  • 0

I trying to make a custom Spinner containing Id and Title. This Spinner displays Title but everywhere in my code I can access to selected Id. how can I do it. it’s like ComboBox in C#.
thanks.

  • 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-17T13:09:12+00:00Added an answer on June 17, 2026 at 1:09 pm

    I solved It!
    At first I created a custom adapter:

    public class SimpleCustomeAdapter extends ArrayAdapter<String>{
    
    Context c;
    List<String> id;
    List<String> title;
    public SimpleCustomeAdapter(Context context, int textViewResourceId,List<String> id, List<String> title) {
    
        super(context, textViewResourceId,id);
    
        c=context;
        this.id=id;
        this.title=title;
    }
    
    @Override
    public View getDropDownView(int position, View convertView,ViewGroup parent) {
    
        return getCustomView(position, convertView, parent);        
    }
    
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        return getCustomView(position, convertView, parent);
    }
    
    public View getCustomView(int position, View convertView, ViewGroup parent) {
        this.setDropDownViewResource(R.layout.spinner_layout);
    
        LayoutInflater inflater=LayoutInflater.from(c);
        View row=inflater.inflate(R.layout.spinner_layout, parent, false);
        TextView idTextView=(TextView)row.findViewById(R.id.idCustomspinnertextView);
        idTextView.setText(id.get(position));
    
        TextView titleTextView=(TextView)row.findViewById(R.id.titleCustomspinnertextView);
        titleTextView.setText(title.get(position));
    
        Typeface externalFont=Typeface.createFromAsset(c.getAssets(), "font/BKOODB.TTF");
        titleTextView.setTypeface(externalFont);
        titleTextView.setTextSize(25);
        return row;
    }
    

    }

    and then, I created a custom Spinner:

    public class CustomSpinner extends Spinner {
    public CustomSpinner(Context context, AttributeSet attrs, int defStyle,
            int mode) {
        super(context, attrs, defStyle, mode);
        // TODO Auto-generated constructor stub
    }
    
    public CustomSpinner(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
    }
    
    public CustomSpinner(Context context, int mode) {
        super(context, mode);
        // TODO Auto-generated constructor stub
    }
    
    List<String> idList;
    List<String> titleList;
    public void setAdapter(SimpleCustomeAdapter adapter) {
        // TODO Auto-generated method stub
        super.setAdapter(adapter);
        this.idList= adapter.id;
        this.titleList = adapter.title;
    }
    
    public void setSelectedId(long id){
        for (int i = 0; i < idList.size(); i++) {
            if(idList.get(i).contains(id+""))
            {
                this.setSelection(i);
                break;
            }
        }
        Log.d("SpinnerError", "This id is not in adapter!");
    }
    
    public CustomSpinner(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
    }
    

    }

    Now in my activity code is like this:

        public class MyActivity extends Activity {
    
    CustomSpinner customspinner1;
    Button button1;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my);
    
        customspinner1=(CustomSpinner)findViewById(R.id.customSpinner1);
        button1=(Button) findViewById(R.id.button1);
    
        List<String> payoffTypeList = new ArrayList<String>();
        List<String> payoffTypeIdList = new ArrayList<String>();
    
        DatabaseAccess dba = new DatabaseAccess(this);
    
        Cursor cur = dba.getAllPayofftype();
        if (cur.moveToFirst()) {
            do {
                payoffTypeList.add(cur.getString(1));
                payoffTypeIdList.add(cur.getString(0));
            } while (cur.moveToNext());
        }
    
    
    
        customspinner1.setAdapter(new SimpleCustomeAdapter(this, R.layout.spinner_layout,payoffTypeIdList, payoffTypeList));
    
        ///example
        customspinner1.setSelectedId(12);
    
        button1.setOnClickListener(new OnClickListener() {
    
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Log.d("myTag", "SlectedId = "+customspinner1.getSelectedId());
            }
        });
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make custom control (like UIButton) manually which can recognize user's touch.
I am trying to make Custom RelativeLayout which can scale and scroll. Right now
I'm trying to make a custom view in Django admin. I'm reading from this
I am trying to make a custom Flex tooltip a la this tutorial .
I'm trying to make a custom converter that inherits from DependencyObject , but it
I am trying to make a custom style for android spinner, however there are
I'm trying to make custom seekbar background. In examples I can find it is
I am trying to make a custom pop up message, that appears, displays to
I'm trying to make a custom UINavigationBar, but the problem is that my background
I was trying to make a custom application form. I've added some control like

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.