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:org.totschnig.myexpenses.dialog.DialogUtils.java

public static Spinner configureTypeSpinner(View view, Context context) {
    Spinner spinner = (Spinner) view.findViewById(R.id.AccountType);
    ArrayAdapter<AccountType> typAdapter = new ArrayAdapter<>(context, android.R.layout.simple_spinner_item,
            android.R.id.text1, AccountType.values());
    typAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(typAdapter);
    return spinner;
}

From source file:org.totschnig.myexpenses.dialog.DialogUtils.java

public static Spinner configureDateFormat(View view, Context context, String prefName) {
    Spinner spinner = (Spinner) view.findViewById(R.id.DateFormat);
    ArrayAdapter<QifDateFormat> dateFormatAdapter = new ArrayAdapter<>(context,
            android.R.layout.simple_spinner_item, QifDateFormat.values());
    dateFormatAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(dateFormatAdapter);
    QifDateFormat qdf;//www .j  a  va2  s. c om
    try {
        qdf = QifDateFormat.valueOf(MyApplication.getInstance().getSettings().getString(prefName, "EU"));
    } catch (IllegalArgumentException e) {
        qdf = QifDateFormat.EU;
    }
    spinner.setSelection(qdf.ordinal());
    return spinner;
}

From source file:org.totschnig.myexpenses.dialog.DialogUtils.java

public static Spinner configureCurrencySpinner(View view, Context context,
        AdapterView.OnItemSelectedListener listener) {
    Spinner spinner = (Spinner) view.findViewById(R.id.Currency);
    ArrayAdapter<CurrencyEnum> curAdapter = new ArrayAdapter<>(context, android.R.layout.simple_spinner_item,
            android.R.id.text1, CurrencyEnum.sortedValues());
    curAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(curAdapter);
    spinner.setOnItemSelectedListener(listener);
    spinner.setSelection(//from w ww.j a v  a  2 s .  com
            curAdapter.getPosition(CurrencyEnum.valueOf(Utils.getLocalCurrency().getCurrencyCode())));
    return spinner;
}

From source file:br.com.bioscada.apps.biotracks.util.AccountUtils.java

/**
 * Sets up account spinner./*from   w w w. java 2 s.  c o  m*/
 * 
 * @param fragmentActivity tyhe fragment activity
 * @param spinner the spinner
 * @param accounts the accounts
 */
public static void setupAccountSpinner(FragmentActivity fragmentActivity, Spinner spinner, Account[] accounts) {
    if (accounts.length > 1) {
        String shareTrackAccount = PreferencesUtils.getString(fragmentActivity,
                R.string.share_track_account_key, PreferencesUtils.SHARE_TRACK_ACCOUNT_DEFAULT);
        ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(fragmentActivity,
                R.layout.account_spinner_item);
        int selection = 0;
        for (int i = 0; i < accounts.length; i++) {
            String name = accounts[i].name;
            adapter.add(name);
            if (name.equals(shareTrackAccount)) {
                selection = i;
            }
        }
        adapter.setDropDownViewResource(R.layout.account_spinner_dropdown_item);
        spinner.setAdapter(adapter);
        spinner.setSelection(selection);
    }
}

From source file:com.sino.conerimageview.ExampleActivity.java

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

    setContentView(R.layout.example_activity);

    //    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    Spinner navSpinner = (Spinner) findViewById(R.id.spinner_nav);

    navSpinner.setAdapter(ArrayAdapter.createFromResource(navSpinner.getContext(), R.array.action_list,
            android.R.layout.simple_spinner_dropdown_item));

    navSpinner.setOnItemSelectedListener(this);

    if (savedInstanceState == null) {
        navSpinner.setSelection(0);/*from w  w  w  . j a v a2 s.  c  o m*/
    }
}

From source file:com.bar.roundedimageview.example.ExampleActivity.java

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

    setContentView(R.layout.example_activity);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    Spinner navSpinner = (Spinner) findViewById(R.id.spinner_nav);

    navSpinner.setAdapter(ArrayAdapter.createFromResource(navSpinner.getContext(), R.array.action_list,
            android.R.layout.simple_spinner_dropdown_item));

    navSpinner.setOnItemSelectedListener(this);

    if (savedInstanceState == null) {
        navSpinner.setSelection(0);//w  ww  . j a v  a2 s .co  m
    }
}

From source file:com.github.johnpersano.supertoasts.demo.fragments.AttributeSpinnerFragment.java

@Nullable
@Override/*  ww w .  j  a  v  a  2  s .com*/
@SuppressWarnings("ConstantConditions")
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_attribute_spinner, container, false);

    if (this.getArguments() == null) {
        throw new IllegalArgumentException(
                getClass().getName().concat(" cannot be " + "instantiated without arguments."));
    }

    final TextView titleTextView = (TextView) view.findViewById(R.id.title);
    titleTextView.setText(getArguments().getString(ARG_SUBTITLE));

    final TextView summaryTextView = (TextView) view.findViewById(R.id.summary);
    summaryTextView.setText(getArguments().getString(ARG_SUMMARY));

    final Spinner spinner = (Spinner) view.findViewById(R.id.spinner);
    spinner.setAdapter(new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_dropdown_item,
            getArguments().getStringArray(ARG_ARRAY_ID)));
    spinner.setSelection(PreferenceManager.getDefaultSharedPreferences(getActivity())
            .getInt(getArguments().getString(ARG_TITLE), 0));
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            PreferenceManager.getDefaultSharedPreferences(getActivity()).edit()
                    .putInt(getArguments().getString(ARG_TITLE), position).commit();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            // Do nothing
        }
    });

    return view;
}

From source file:it.polimi.wifidirect.dialog.PingPongDialog.java

/**
 * Method to set the Spinner adapter.//w w w.j a  va2  s . c o  m
 * @param spinner The Spinner to set
 * @param list ArrayList<SpinnerRow> of the element to fill the Spinner.
 */
private void setSpinnerAdapter(Spinner spinner, ArrayList<SpinnerRow> list) {
    spinner.setAdapter(
            new CustomSpinnerAdapter(this.getActivity(), android.R.layout.simple_spinner_item, list));
}

From source file:com.github.michalbednarski.intentslab.editor.NewBundleEntryDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    // Inflate layout
    View view = getActivity().getLayoutInflater().inflate(R.layout.add_extra, null);

    // Find and fill name field
    Bundle arguments = getArguments();/*from w ww  .j  av a  2  s. co  m*/
    final TextView nameTextView = (TextView) view.findViewById(R.id.name);
    if (arguments != null) {
        nameTextView.setText(arguments.getString(ARG_DEFAULT_NAME));
    }

    // Find and fill type Spinner
    final Spinner typeSpinner = (Spinner) view.findViewById(R.id.typespinner);
    typeSpinner.setAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item,
            new String[] { "String/Number", // 0 = TYPE_STRING_OR_NUMBER
                    "Boolean" // 1 = TYPE_BOOLEAN
            }));

    // Create AlertDialog
    return new AlertDialog.Builder(getActivity()).setTitle(R.string.btn_add).setView(view)
            .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String name = nameTextView.getText().toString();
                    switch (typeSpinner.getSelectedItemPosition()) {
                    case TYPE_STRING_OR_NUMBER:
                        getBundleAdapter().launchEditorForNewEntry(name, "");
                        break;
                    case TYPE_BOOLEAN:
                        getBundleAdapter().onEditorResult(name, true);
                        break;
                    }
                }
            }).create();
}

From source file:dev.petercp.baccalculator.AddDriverActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_add_driver);

    if (getSupportActionBar() != null)
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item,
            new String[] { "Hombre", "Mujer" });
    Spinner genderSpinner = (Spinner) findViewById(R.id.input_gender);
    genderSpinner.setAdapter(adapter);
}