Solved

Drop Down Menu android widget besides 'spinner'

Posted on 2011-03-08
2
1,206 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

As the title indicates, I have done this before. It chills me everytime I update the OS on my phone, (http://www.experts-exchange.com/articles/18084/Upgrading-to-Android-5-0-Lollipop.html) because one time I did this and I essentially had a bricked …
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.
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…

734 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