Example usage for android.widget Spinner setAdapter

List of usage examples for android.widget Spinner setAdapter

Introduction

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

Prototype

@Override
public void setAdapter(SpinnerAdapter adapter) 

Source Link

Document

Sets the SpinnerAdapter used to provide the data which backs this Spinner.

Usage

From source file:com.greenapp.wavecast.MapInfographActivity.java

@Override
protected void startDemo() {
    getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(43.652527, -79.38196), 4));

    // Set up the spinner/dropdown list
    Spinner spinner = (Spinner) findViewById(R.id.spinner);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.heatmaps_datasets_array,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    spinner.setOnItemSelectedListener(new SpinnerActivity());

    try {//from www .  j a  va 2  s.  c om
        mLists.put(getString(R.string.police_stations),
                new DataSet(readItems(R.raw.police), getString(R.string.police_stations_url)));
        mLists.put(getString(R.string.medicare),
                new DataSet(readItems(R.raw.medicare), getString(R.string.medicare_url)));
    } catch (JSONException e) {
        Toast.makeText(this, "Problem reading list of markers.", Toast.LENGTH_LONG).show();
    }

    // Make the handler deal with the map
    // Input: list of WeightedLatLngs, minimum and maximum zoom levels to calculate custom
    // intensity from, and the map to draw the heatmap on
    // radius, gradient and opacity not specified, so default are used
}

From source file:com.example.joeroger.homework2.activity.WeatherActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Turn on strict mode in debug builds
    if (BuildConfig.DEBUG) {
        StrictMode.enableDefaults();//from  w w  w .java 2s.co m
    }

    setContentView(R.layout.activity_weather);

    setSupportActionBar((Toolbar) findViewById(R.id.toolBar));
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayShowTitleEnabled(false);
        Spinner spinner = (Spinner) findViewById(R.id.city_spinner);
        citySpinnerCursorAdapter = new CitySpinnerCursorAdapter(actionBar.getThemedContext(), null);
        spinner.setAdapter(citySpinnerCursorAdapter);
        spinner.setOnItemSelectedListener(this);
        ViewCompat.setElevation(spinner, 0);
    }

    HandlerThread handlerThread = new HandlerThread("WeatherActivityThread");
    handlerThread.start();
    handler = new Handler(handlerThread.getLooper(), this);

    resolvingError = savedInstanceState != null && savedInstanceState.getBoolean(STATE_RESOLVING_ERROR);

    CityConditionsLoaderCallbacks.initLoader(getSupportLoaderManager(), this, this,
            CitySpinnerCursorAdapter.PROJECTION, CityConditionsContract.WHERE_CURRENT_OR_FAVORITE,
            CityConditionsContract.WHERE_CURRENT_OR_FAVORITE_ARGS);
}

From source file:com.coinblesk.client.ui.dialogs.CurrencyDialogFragment.java

@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    LayoutInflater inflater = getActivity().getLayoutInflater();
    final View view = inflater.inflate(R.layout.fragment_currency_dialog, null);

    final Spinner spinner = (Spinner) view.findViewById(R.id.currency_spinner);
    ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(), R.layout.spinner_item,
            Constants.CURRENCIES);// w ww.  j a va2 s  .  c  om
    spinner.setSelection(0, false);
    spinner.setAdapter(adapter);

    final TextView usd = (TextView) view.findViewById(R.id.usd);
    final TextView eur = (TextView) view.findViewById(R.id.eur);

    final TextView btc = (TextView) view.findViewById(R.id.btc);
    final TextView mbtc = (TextView) view.findViewById(R.id.mbtc);
    final TextView ubtc = (TextView) view.findViewById(R.id.ubtc);

    final View[] viewsBTC = new View[] { btc, mbtc, ubtc };
    final View[] viewsFiat = new View[] { usd, eur, spinner };

    final AlertDialog d = new AlertDialog.Builder(getActivity()).setTitle(R.string.change_currency)
            .setView(view).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    broadcastExchangeRateChanged(getActivity());
                }
            }).create();

    btc.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            for (View v : viewsBTC) {
                v.setBackgroundResource(R.drawable.cell_shape);
            }
            view.setBackgroundResource(R.drawable.cell_shape_currency);
            SharedPrefUtils.setBitcoinScalePrefix(getActivity(), "BTC");
        }
    });

    mbtc.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            for (View v : viewsBTC) {
                v.setBackgroundResource(R.drawable.cell_shape);
            }
            view.setBackgroundResource(R.drawable.cell_shape_currency);
            SharedPrefUtils.setBitcoinScalePrefix(getActivity(), "mBTC");
        }
    });

    ubtc.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            for (View v : viewsBTC) {
                v.setBackgroundResource(R.drawable.cell_shape);
            }
            view.setBackgroundResource(R.drawable.cell_shape_currency);
            SharedPrefUtils.setBitcoinScalePrefix(getActivity(), "BTC");
        }
    });

    usd.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            for (View v : viewsFiat) {
                v.setBackgroundResource(R.drawable.cell_shape);
            }
            view.setBackgroundResource(R.drawable.cell_shape_currency);
            SharedPrefUtils.setCurrency(getActivity(), "USD");
        }
    });

    eur.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            for (View v : viewsFiat) {
                v.setBackgroundResource(R.drawable.cell_shape);
            }
            view.setBackgroundResource(R.drawable.cell_shape_currency);
            SharedPrefUtils.setCurrency(getActivity(), "EUR");
        }
    });

    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (position == 0) {
                return;
            }
            for (View v : viewsFiat) {
                v.setBackgroundResource(R.drawable.cell_shape);
            }
            spinner.setBackgroundResource(R.drawable.cell_shape_currency);
            SharedPrefUtils.setCurrency(getActivity(), Constants.CURRENCIES[position]);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            //activateSpinner(s, usd, eur);
        }
    });

    loadSettings(getActivity(), btc, mbtc, ubtc, usd, eur, spinner);

    return d;
}

From source file:me.johnmh.boogdroid.ui.BugStatusFragment.java

@NonNull
private Spinner setupSpinnerResolution(View view) {
    Spinner spinnerResolution = (Spinner) view.findViewById(R.id.resolution);
    BugResolutionChanges resolutionValues = bug.getProduct().getServer().getResolutionValues();
    ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity().getBaseContext(),
            android.R.layout.simple_spinner_item, resolutionValues);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinnerResolution.setAdapter(adapter);
    spinnerResolution.setSelection(adapter.getPosition(bug.getResolution()));
    return spinnerResolution;
}

From source file:com.commonsware.android.contacts.spinners.ContactSpinners.java

@Override
public void onReady() {
    setContentView(R.layout.main);// w w w . j  a  v  a 2 s  .  co  m

    Spinner spin = findViewById(R.id.spinner);
    spin.setOnItemSelectedListener(this);

    ArrayAdapter<String> aa = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
            getResources().getStringArray(R.array.options));

    aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spin.setAdapter(aa);

    RecyclerView rv = findViewById(android.R.id.list);

    rv.setLayoutManager(new LinearLayoutManager(this));
    rv.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
    adapter = new RVCursorAdapter(getLayoutInflater());
    rv.setAdapter(adapter);
}

From source file:org.runbuddy.tomahawk.adapters.ViewHolder.java

public void fillHeaderView(ArrayList<CharSequence> spinnerItems, int initialSelection,
        AdapterView.OnItemSelectedListener listener) {
    ArrayAdapter<CharSequence> adapter = new ArrayAdapter<>(TomahawkApp.getContext(),
            R.layout.dropdown_header_textview, spinnerItems);
    adapter.setDropDownViewResource(R.layout.dropdown_header_dropdown_textview);
    Spinner spinner = (Spinner) findViewById(R.id.spinner1);
    spinner.setAdapter(adapter);
    spinner.setSelection(initialSelection);
    spinner.setOnItemSelectedListener(listener);
}

From source file:org.mifos.androidclient.templates.OperationFormActivity.java

public Spinner addComboBoxFormField(String fieldLabel, List<String> elements) {
    LinearLayout field = (LinearLayout) getLayoutInflater().inflate(R.layout.combo_box_form_field, null);
    TextView label = (TextView) field.findViewById(R.id.comboBoxFormField_label);
    label.setText(fieldLabel);//from   w w  w.  jav  a 2  s.c  om
    Spinner input = (Spinner) field.findViewById(R.id.comboBoxFormField_input);
    input.setPrompt(fieldLabel);
    input.setAdapter(new ArrayAdapter(this, R.layout.combo_box_item, elements));
    mFormFields.addView(field, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    return input;
}

From source file:com.currency.org.CurrencyConverterActivity.java

/** Called when the activity is first created. */
@Override/*from  w w w .ja  v a 2s.  c om*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Spinner s1 = (Spinner) findViewById(R.id.spinner1);
    Spinner s2 = (Spinner) findViewById(R.id.spinner2);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.name,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.select_dialog_singlechoice);
    val = getResources().getStringArray(R.array.value);
    s1.setAdapter(adapter);
    s2.setAdapter(adapter);
    s1.setOnItemSelectedListener(new spinOne(1));
    s2.setOnItemSelectedListener(new spinOne(2));
    Button b = (Button) findViewById(R.id.button1);
    b.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            TextView t = (TextView) findViewById(R.id.textView4);
            if (from == to) {
                Toast.makeText(getApplicationContext(), "Invalid", 4000).show();
            } else {
                try {
                    s = getJson(
                            "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20(%22"
                                    + val[from] + val[to]
                                    + "%22)&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=");
                    JSONObject jObj;
                    jObj = new JSONObject(s);
                    String exResult = jObj.getJSONObject("query").getJSONObject("results").getJSONObject("rate")
                            .getString("Rate");
                    t.setText(exResult);
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (ClientProtocolException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    });
}

From source file:org.catrobat.catroid.content.bricks.BroadcastBrick.java

@Override
public View getPrototypeView(Context context) {
    View prototypeView = View.inflate(context, R.layout.brick_broadcast, null);
    Spinner broadcastSpinner = (Spinner) prototypeView.findViewById(R.id.brick_broadcast_spinner);
    broadcastSpinner.setFocusableInTouchMode(false);
    broadcastSpinner.setFocusable(false);
    broadcastSpinner.setEnabled(false);/*ww w .  j  a  v  a 2  s  . c o  m*/

    SpinnerAdapter broadcastSpinnerAdapter = MessageContainer.getMessageAdapter(context);
    broadcastSpinner.setAdapter(broadcastSpinnerAdapter);
    setSpinnerSelection(broadcastSpinner);
    return prototypeView;
}

From source file:hku.fyp14017.blencode.content.bricks.BroadcastBrick.java

@Override
public View getPrototypeView(Context context) {
    View prototypeView = View.inflate(context, hku.fyp14017.blencode.R.layout.brick_broadcast, null);
    Spinner broadcastSpinner = (Spinner) prototypeView
            .findViewById(hku.fyp14017.blencode.R.id.brick_broadcast_spinner);
    broadcastSpinner.setFocusableInTouchMode(false);
    broadcastSpinner.setFocusable(false);
    SpinnerAdapter broadcastSpinnerAdapter = MessageContainer.getMessageAdapter(context);
    broadcastSpinner.setAdapter(broadcastSpinnerAdapter);
    setSpinnerSelection(broadcastSpinner);
    return prototypeView;
}