Solved

Drop Down Menu android widget besides 'spinner'

Posted on 2011-03-08
2
1,197 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
computer science syllabus 3 88
SIM enable  androde  TAB 3 70
iPhone v Android phone 7 58
Delete Android all or certain applications data programmatically 9 66
Working settings for French ISP Orange "Prêt à Surfer" SIM cards for data connections only. Can't be found anywhere else !
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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.
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

809 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