Example usage for android.widget Spinner Spinner

List of usage examples for android.widget Spinner Spinner

Introduction

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

Prototype

public Spinner(Context context, AttributeSet attrs) 

Source Link

Document

Constructs a new spinner with the given context's theme and the supplied attribute set.

Usage

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

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

    _options = options;//w w  w. ja v a  2 s  . c  o m

    _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);
}

From source file:ru.adios.budgeter.widgets.DataTableLayout.java

private void loadDataAndPopulateTable() {
    new AsyncTask<DataStore, Void, Integer>() {
        @Override/*  ww w.  j av  a  2  s  .  c  o  m*/
        protected Integer doInBackground(DataStore... params) {
            return params[0].count();
        }

        @Override
        protected void onPostExecute(Integer c) {
            count = c;
            if (c == 0) {
                insertNoDataRow();
                tablePopulated = true;
                if (listener.isPresent()) {
                    listener.get().accept(DataTableLayout.this);
                }
                invalidate();
                return;
            }

            if (currentPage == 0) {
                turnToPage(1, false);
            }
            if (c > pageSize) {
                final Context context = getContext();

                if (tableName.isPresent()) {
                    pageSizeSpinner = new Spinner(context, Spinner.MODE_DROPDOWN);
                    pageSizeSpinner.setMinimumWidth(UiUtils.dpAsPixels(context, 70));
                    pageSizeSpinner.setId(ElementsIdProvider.getNextId());
                    final List<Integer> contents = getPageSpinnerContents();
                    spinnerContents = Optional.of(contents);
                    pageSizeSpinner.setAdapter(new ArrayAdapter<>(context, android.R.layout.simple_spinner_item,
                            android.R.id.text1, contents));
                    pageSizeSpinner.setSelection(contents.indexOf(pageSize));
                    pageSizeSpinner.setLayoutParams(new LinearLayout.LayoutParams(
                            TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT, 2f));
                    pageSizeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                        @Override
                        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                            setPageSize((Integer) parent.getAdapter().getItem(position));
                        }

                        @Override
                        public void onNothingSelected(AdapterView<?> parent) {
                        }
                    });
                    pageSizeSpinner.setVisibility(VISIBLE);

                    if (!titleView.isPresent()) {
                        addTitleRowWithSeparator(context, 10f, 8f);
                    } else {
                        titleView.get().setWeightSum(10f);
                        titleView.get().getChildAt(0).setLayoutParams(
                                new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                                        LinearLayout.LayoutParams.WRAP_CONTENT, 8f));
                    }
                    titleView.get().addView(pageSizeSpinner, 0);
                }
                final TableRow.LayoutParams fp = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,
                        TableRow.LayoutParams.WRAP_CONTENT, 1f);
                fp.span = itemsPerInnerRow;
                footer.setLayoutParams(fp);
                footer.setVisibility(VISIBLE);
                populateFooter();
            }
            loadTableProcedures();
        }
    }.execute(dataStore);
}