Solved

Drop Down Menu android widget besides 'spinner'

Posted on 2011-03-08
2
1,173 Views
Last Modified: 2012-05-11
Is there a drop down menu widget that can be run from the top of a GUI besides th spinner ?
The spinner does not work the way I need it for my application. Specifically I need a header to display instead of the first option of the spinner widget.  

                                                                         Thanks,
                                                                         Bob H
0
Comment
Question by:hums
2 Comments
 
LVL 17

Accepted Solution

by:
Dejan Pažin earned 125 total points
ID: 35082817

You dont need much to achieve what you are after. Simply create your own ArrayAdapter and use it for the Spinner. Here is an example.


import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;

public class MyActivity extends Activity {


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LinearLayout ll = new LinearLayout(this);
        setContentView(ll);

        Spinner spinner = new Spinner(this);
        MyAdapter spinnerArrayAdapter = new MyAdapter(this, android.R.layout.simple_spinner_item, new String[]{"a", "b", "c"});
        spinner.setAdapter(spinnerArrayAdapter);
        ll.addView(spinner);
    }

    private class MyAdapter extends ArrayAdapter{
        private TextView headerView;

        public MyAdapter(Context context, int textViewResourceId, Object[] objects) {
            super(context, textViewResourceId, objects);
            headerView = new TextView(context);
            headerView.setText("My header");
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            return headerView;
        }
    }
}

Open in new window

0
 

Author Closing Comment

by:hums
ID: 35082966
Thanks for the information.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I recently asked a question (http://www.experts-exchange.com/Programming/Smartphones/Android/Q_28684946.html) about Computer Inventory applications for Mobile Devices.  I was specifically interested in an app I could use on my android phone.  The be…
Introduction This article is a continuation of Part-1 as evident from the title. Please visit this page (http://www.experts-exchange.com/articles/18706/Backing-up-personal-data-on-your-Android-device-Part-1.html) to read the earlier Part -1. If y…
This video is in connection to the article "The case of a missing mobile phone (https://www.experts-exchange.com/articles/28474/The-Case-of-a-Missing-Mobile-Phone.html)". It will help one to understand clearly the steps to track a lost android phone.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now