Solved

Drop Down Menu android widget besides 'spinner'

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

This is an explanation of a simple data model to help parse a JSON feed
Here, we have shared an easy step by step tutorial on how to download instagram images and videos on PC, Android Mobile and iOS mobile.
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.

772 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