Example usage for android.widget Spinner MODE_DIALOG

List of usage examples for android.widget Spinner MODE_DIALOG

Introduction

In this page you can find the example usage for android.widget Spinner MODE_DIALOG.

Prototype

int MODE_DIALOG

To view the source code for android.widget Spinner MODE_DIALOG.

Click Source Link

Document

Use a dialog window for selecting spinner options.

Usage

From source file:com.ternup.caddisfly.widget.FormSpinner.java

public FormSpinner(Context context, String property, JSONObject options) {
    super(context, property);

    _options = options;/*from   w ww  .j  ava2  s .  c om*/

    _spinner = new Spinner(context, Spinner.MODE_DIALOG);
    //_spinner.setLayoutParams( FormActivity.defaultLayoutParams );

    String p;
    String name;

    _propertyMap = new HashMap<String, String>();
    _adapter = new ArrayAdapter<String>(context, android.R.layout.simple_spinner_item);
    _adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    _spinner.setAdapter(_adapter);
    _spinner.setSelection(0);

    try {
        if (options != null) {
            JSONArray propertyNames = options.names();
            for (int i = 0; i < options.length(); i++) {
                name = propertyNames.getString(i);
                p = options.getString(name);

                _adapter.add(p);
                _propertyMap.put(p, name);
            }
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }

    LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);

    params1.bottomMargin = 15;
    params1.topMargin = 0;

    _spinner.setLayoutParams(params1);

    _layout.addView(_spinner);
}