?
Solved

Drop Down Menu android widget besides 'spinner'

Posted on 2011-03-08
2
Medium Priority
?
1,218 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 500 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Learn how to use the free Acronis True Image app to easily transfer data between iPhones and Android phones.
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.
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…

718 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