I want a Button pull up a menu like a Spinner but it doesn't need to store data like the prompt in a Spinner.
A Spinner looks like this:
Spinner spinner = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.social_list, android.R.layout.simple_gallery_item);//select_dialog_multichoice);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
I need to work same thing as a Button... Thanks
i think you should put spinner.performClick();
on button click method
You can make use of ContextMenu . Here is a link about Context Menu Demo.
http://mobile.dzone.com/news/context-menu-android-tutorial
But little modifications are required. Inside the button click event, you have to open the ContextMenu.
just open the dialog with list on button click will be looks same as spinner .....
as in
http://saga-androidapplication.blogspot.in/2011/05/dialog-list-item.html
http://developer.android.com/guide/topics/ui/dialogs.html#AddingAList
use Resources res = getResources();
final String[] items = res.getStringArray(R.array.social_list);
//final CharSequence[] items = {"Red", "Green", "Blue"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Pick a color");
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
}
});
AlertDialog alert = builder.create();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.