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.makotogo.mobile.hoursdroid.HoursDetailFragment.java

private void configureProjectSpinner(View view) {
    final Spinner projectSpinner = (Spinner) view.findViewById(R.id.spinner_hours_detail_project);
    projectSpinner.setEnabled(isThisHoursRecordNotActive());
    if (isThisHoursRecordActive()) {
        projectSpinner.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.no_border, null));
    } else {/* ww w.j  av a 2 s . c  o  m*/
        projectSpinner
                .setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.rounded_border, null));
    }
    projectSpinner.setAdapter(new AbstractArrayAdapter(getActivity(), R.layout.project_list_row) {
        @Override
        protected ViewBinder<Project> createViewBinder() {
            return new ProjectViewBinder();
        }
    });
    projectSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            Project project = (Project) projectSpinner.getAdapter().getItem(position);
            if (project == Project.MANAGE_PROJECTS) {
                // Launch the Project List Screen
                Intent intent = new Intent(getActivity(), ProjectListActivity.class);
                intent.putExtra(ProjectListActivity.EXTRA_JOB, mHours.getJob());
                //Toast.makeText(getActivity(), "Launching ProjectListActivity (eventually)...", Toast.LENGTH_LONG).show();
                startActivityForResult(intent, REQUEST_CODE_MANAGE_PROJECTS);
            } else {
                // Active project has changed. Update the UI.
                mHours.setProject(project);
                updateUI();
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            // Nothing to do
        }
    });
}

From source file:com.adithya321.sharesanalysis.fragments.PurchaseShareFragment.java

@Nullable
@Override/* ww  w  .j  av  a2s.  co  m*/
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_share_purchase, container, false);

    databaseHandler = new DatabaseHandler(getContext());
    sharePurchasesRecyclerView = (RecyclerView) root.findViewById(R.id.share_purchases_recycler_view);
    emptyTV = (TextView) root.findViewById(R.id.empty);
    arrow = (ImageView) root.findViewById(R.id.arrow);
    setRecyclerViewAdapter();

    FloatingActionButton addPurchaseFab = (FloatingActionButton) root.findViewById(R.id.add_purchase_fab);
    addPurchaseFab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final Dialog dialog = new Dialog(getContext());
            dialog.setTitle("Add Share Purchase");
            dialog.setContentView(R.layout.dialog_add_share_purchase);
            dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
                    WindowManager.LayoutParams.WRAP_CONTENT);
            dialog.show();

            final AutoCompleteTextView name = (AutoCompleteTextView) dialog.findViewById(R.id.share_name);
            List<String> nseList = ShareUtils.getNseList(getContext());
            ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(getContext(),
                    android.R.layout.simple_dropdown_item_1line, nseList);
            name.setAdapter(arrayAdapter);

            final Spinner spinner = (Spinner) dialog.findViewById(R.id.existing_spinner);
            ArrayList<String> shares = new ArrayList<>();
            for (Share share : sharesList) {
                shares.add(share.getName());
            }
            ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(getContext(),
                    android.R.layout.simple_spinner_item, shares);
            spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            spinner.setAdapter(spinnerAdapter);

            final RadioButton newRB = (RadioButton) dialog.findViewById(R.id.radioBtn_new);
            RadioButton existingRB = (RadioButton) dialog.findViewById(R.id.radioBtn_existing);
            if (shares.size() == 0)
                existingRB.setVisibility(View.GONE);
            (newRB).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    name.setVisibility(View.VISIBLE);
                    spinner.setVisibility(View.GONE);
                }
            });

            (existingRB).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    name.setVisibility(View.GONE);
                    spinner.setVisibility(View.VISIBLE);
                }
            });

            Calendar calendar = Calendar.getInstance();
            year_start = calendar.get(Calendar.YEAR);
            month_start = calendar.get(Calendar.MONTH) + 1;
            day_start = calendar.get(Calendar.DAY_OF_MONTH);
            final Button selectDate = (Button) dialog.findViewById(R.id.select_date);
            selectDate.setText(new StringBuilder().append(day_start).append("/").append(month_start).append("/")
                    .append(year_start));
            selectDate.setOnClickListener(this);

            Button addPurchaseBtn = (Button) dialog.findViewById(R.id.add_purchase_btn);
            addPurchaseBtn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Share share = new Share();
                    share.setId(databaseHandler.getNextKey("share"));
                    share.setPurchases(new RealmList<Purchase>());
                    Purchase purchase = new Purchase();
                    purchase.setId(databaseHandler.getNextKey("purchase"));

                    if (newRB.isChecked()) {
                        String sName = name.getText().toString().trim();
                        if (sName.equals("")) {
                            Toast.makeText(getActivity(), "Invalid Name", Toast.LENGTH_SHORT).show();
                            return;
                        } else {
                            share.setName(sName);
                            purchase.setName(sName);
                        }
                    }

                    String stringStartDate = year_start + " " + month_start + " " + day_start;
                    DateFormat format = new SimpleDateFormat("yyyy MM dd", Locale.ENGLISH);
                    try {
                        Date date = format.parse(stringStartDate);
                        share.setDateOfInitialPurchase(date);
                        purchase.setDate(date);
                    } catch (Exception e) {
                        Toast.makeText(getActivity(), "Invalid Date", Toast.LENGTH_SHORT).show();
                        return;
                    }

                    EditText quantity = (EditText) dialog.findViewById(R.id.no_of_shares);
                    try {
                        purchase.setQuantity(Integer.parseInt(quantity.getText().toString()));
                    } catch (Exception e) {
                        Toast.makeText(getActivity(), "Invalid Number of Shares", Toast.LENGTH_SHORT).show();
                        return;
                    }

                    EditText price = (EditText) dialog.findViewById(R.id.buying_price);
                    try {
                        purchase.setPrice(Double.parseDouble(price.getText().toString()));
                    } catch (Exception e) {
                        Toast.makeText(getActivity(), "Invalid Buying Price", Toast.LENGTH_SHORT).show();
                        return;
                    }

                    purchase.setType("buy");
                    if (newRB.isChecked()) {
                        if (!databaseHandler.addShare(share, purchase)) {
                            Toast.makeText(getActivity(), "Share Already Exists", Toast.LENGTH_SHORT).show();
                            return;
                        }
                    } else {
                        purchase.setName(spinner.getSelectedItem().toString());
                        databaseHandler.addPurchase(spinner.getSelectedItem().toString(), purchase);
                    }
                    setRecyclerViewAdapter();
                    dialog.dismiss();
                }
            });
        }
    });

    return root;
}

From source file:com.ayuget.redface.ui.activity.ReplyActivity.java

protected void setupUserSwitcher(LayoutInflater inflater, List<User> users) {
    if (users.size() == 0) {
        Log.e(LOG_TAG, "Empty user list");
    } else if (users.size() == 1 || !canSwitchUser()) {
        View userView = setupUserView(inflater, canSwitchUser() ? users.get(0) : userManager.getActiveUser());
        actionsToolbar.addView(userView);
    } else {//from   w w  w .  j a  v a  2 s . co  m
        // Setup spinner for user selection
        Log.d(LOG_TAG, String.format("Initializing spinner for '%d' users", users.size()));
        View spinnerContainer = inflater.inflate(R.layout.reply_user_spinner, actionsToolbar, false);
        ActionBar.LayoutParams lp = new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT);
        actionsToolbar.addView(spinnerContainer, 0, lp);

        Spinner spinner = (Spinner) spinnerContainer.findViewById(R.id.reply_user_spinner);

        final UserAdapter userAdapter = new UserAdapter(this, users);
        spinner.setAdapter(userAdapter);

        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                User user = userAdapter.getItem(position);
                userManager.setActiveUser(user);
            }

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

From source file:course1778.mobileapp.safeMedicare.Main.FamMemFrag.java

private void add() {
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View addView = inflater.inflate(R.layout.add_edit, null);
    //AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    AlertDialog.Builder builder = new AlertDialog.Builder(
            new ContextThemeWrapper(getContext(), R.style.AlertDialogCustom));

    builder.setTitle(R.string.add_title).setView(addView).setPositiveButton(R.string.ok, this)
            .setNegativeButton(R.string.cancel, null).show();

    Spinner spin = (Spinner) addView.findViewById(R.id.spinner);
    //spin.setOnItemSelectedListener(FamMemActivity.getContext());
    ArrayAdapter<String> aa = new ArrayAdapter<String>(FamMemActivity.getContext(), R.layout.spinner_item_text,
            items);/*  w  w  w .  j a  va  2s . c o  m*/
    aa.setDropDownViewResource(R.layout.spinner_dropdown_item);
    spin.setAdapter(aa);

    // field for user adding medication name
    textView = (AutoCompleteTextView) addView.findViewById(R.id.title);

    /** sheet 1 displays all the drug interactions;
     * sheet 2 displays the list of all drugs
      */
    crsList = med_list.rawQuery("SELECT * FROM Sheet1", null);
    crsInteractions = med_interaction.rawQuery("SELECT * FROM DrugDrug", null);

    String[] array = new String[crsList.getCount()];
    int i = 0;
    while (crsList.moveToNext()) {
        String uname = crsList.getString(crsList.getColumnIndex("Name"));
        array[i] = uname;
        i++;
    }

    // Create the adapter and set it to the AutoCompleteTextView
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(FamMemActivity.getContext(), R.layout.listlayout,
            R.id.listTextView, array);
    textView.setAdapter(adapter);

}

From source file:dynamite.zafroshops.app.fragment.AddZopFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_add_zop, container, false);
    Spinner zopTypeSpinner = (Spinner) rootView.findViewById(R.id.newZopType);
    Spinner zopCountrySpinner = (Spinner) rootView.findViewById(R.id.newZopCountry);

    RelativeLayout loader = (RelativeLayout) rootView.findViewById(R.id.relativeLayoutLoader);
    LinearLayout zop = (LinearLayout) rootView.findViewById(R.id.itemZopAdd);
    TextView text = (TextView) rootView.findViewById(R.id.loading_message);
    final TextView phoneCode = (TextView) rootView.findViewById(R.id.newZopPhoneCode);

    loader.setVisibility(View.INVISIBLE);
    zop.setVisibility(View.VISIBLE);
    text.setText(getString(R.string.sending_data));
    zopTypeSpinner.setAdapter(zopTypeAdapter);
    zopCountrySpinner.setAdapter(zopCountryAdapter);
    zopTypeSpinner.setSelection(zopTypeAdapter.getPosition(ZopType.Shop));

    ((Button) rootView.findViewById(R.id.newZopOpeningsButton))
            .setText(getString(R.string.openings_edit) + " 0/7");
    ((Button) rootView.findViewById(R.id.newZopServicesButton))
            .setText(getString(R.string.services_editing) + " 0/" + ZopServiceType.values().length);
    zopCountrySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override//from  w w w  . j ava2s .c o m
        public void onItemSelected(AdapterView<?> parent, View view, final int position, long id) {
            MobileCountry country = (MobileCountry) parent.getItemAtPosition(position);

            phoneCode.setText(country.PhoneCode);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });
    clearForm(rootView);

    return rootView;
}

From source file:org.openoverlayrouter.noroot.updateConfActivity.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    faActivity = (FragmentActivity) super.getActivity();
    llLayout = (LinearLayout) inflater.inflate(R.layout.updateconf2, container, false);
    setTextHintAlphas();/*from www.j  a v  a 2s.co m*/
    conf_file = new File(sdcardDir, confFile);
    log_file = sdcardDir.getAbsolutePath() + "/oor.log";

    iface_list = ConfigTools.get_ifaces_list();

    MultiSelectionSpinner spinner = (MultiSelectionSpinner) llLayout.findViewById(R.id.IfaceNameSpinner);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(faActivity, android.R.layout.simple_spinner_item,
            iface_list);
    // Specify the layout to use when the list of choices appears
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    // Apply the adapter to the spinner
    spinner.setItems(iface_list);

    Spinner logSpinner = (Spinner) llLayout.findViewById(R.id.LogSpinner);
    ArrayAdapter<CharSequence> logAdapter = ArrayAdapter.createFromResource(faActivity, R.array.LogLevelArray,
            android.R.layout.simple_spinner_item);
    logSpinner.setAdapter(logAdapter);

    if (!conf_file.exists()) {
        createConfFile();
    }

    readConfFileAndFillParameters();

    Button updateConfButton = (Button) llLayout.findViewById(R.id.updateConfButton);
    updateConfButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            updateConfClicked(llLayout);
        }
    });

    CheckBox updateConf_NAT_aware = (CheckBox) llLayout.findViewById(R.id.updateConf_NAT_aware);
    updateConf_NAT_aware.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            updateConfNATAwareClicked(llLayout);
        }
    });

    CheckBox updateCondDNSCheck = (CheckBox) llLayout.findViewById(R.id.updateConfDNSCheck);
    updateCondDNSCheck.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            updateConfDNSClicked(llLayout);
        }
    });

    return llLayout;

}

From source file:nya.miku.wishmaster.ui.settings.AutohideActivity.java

@SuppressLint("InflateParams")
@Override//from  w  w w .j  a v a2 s  . c  o  m
protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    Object item = l.getItemAtPosition(position);
    final int changeId;
    if (item instanceof AutohideRule) {
        changeId = position - 1;
    } else {
        changeId = -1; //-1 - ?  
    }

    Context dialogContext = Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB
            ? new ContextThemeWrapper(this, R.style.Neutron_Medium)
            : this;
    View dialogView = LayoutInflater.from(dialogContext).inflate(R.layout.dialog_autohide_rule, null);
    final EditText regexEditText = (EditText) dialogView.findViewById(R.id.dialog_autohide_regex);
    final Spinner chanSpinner = (Spinner) dialogView.findViewById(R.id.dialog_autohide_chan_spinner);
    final EditText boardEditText = (EditText) dialogView.findViewById(R.id.dialog_autohide_boardname);
    final EditText threadEditText = (EditText) dialogView.findViewById(R.id.dialog_autohide_threadnum);
    final CheckBox inCommentCheckBox = (CheckBox) dialogView.findViewById(R.id.dialog_autohide_in_comment);
    final CheckBox inSubjectCheckBox = (CheckBox) dialogView.findViewById(R.id.dialog_autohide_in_subject);
    final CheckBox inNameCheckBox = (CheckBox) dialogView.findViewById(R.id.dialog_autohide_in_name);

    chanSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, chans));
    if (changeId != -1) {
        AutohideRule rule = (AutohideRule) item;
        regexEditText.setText(rule.regex);
        int chanPosition = chans.indexOf(rule.chanName);
        chanSpinner.setSelection(chanPosition != -1 ? chanPosition : 0);
        boardEditText.setText(rule.boardName);
        threadEditText.setText(rule.threadNumber);
        inCommentCheckBox.setChecked(rule.inComment);
        inSubjectCheckBox.setChecked(rule.inSubject);
        inNameCheckBox.setChecked(rule.inName);
    } else {
        chanSpinner.setSelection(0);
    }

    DialogInterface.OnClickListener save = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            String regex = regexEditText.getText().toString();
            if (regex.length() == 0) {
                Toast.makeText(AutohideActivity.this, R.string.autohide_error_empty_regex, Toast.LENGTH_LONG)
                        .show();
                return;
            }

            try {
                Pattern.compile(regex, Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE | Pattern.DOTALL);
            } catch (Exception e) {
                CharSequence message = null;
                if (e instanceof PatternSyntaxException) {
                    String eMessage = e.getMessage();
                    if (!TextUtils.isEmpty(eMessage)) {
                        SpannableStringBuilder a = new SpannableStringBuilder(
                                getString(R.string.autohide_error_incorrect_regex));
                        a.append('\n');
                        int startlen = a.length();
                        a.append(eMessage);
                        a.setSpan(new TypefaceSpan("monospace"), startlen, a.length(),
                                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                        message = a;
                    }
                }
                if (message == null)
                    message = getString(R.string.error_unknown);
                Toast.makeText(AutohideActivity.this, message, Toast.LENGTH_LONG).show();
                return;
            }

            AutohideRule rule = new AutohideRule();
            int spinnerSelectedPosition = chanSpinner.getSelectedItemPosition();
            rule.regex = regex;
            rule.chanName = spinnerSelectedPosition > 0 ? chans.get(spinnerSelectedPosition) : ""; // 0 ? = ? 
            rule.boardName = boardEditText.getText().toString();
            rule.threadNumber = threadEditText.getText().toString();
            rule.inComment = inCommentCheckBox.isChecked();
            rule.inSubject = inSubjectCheckBox.isChecked();
            rule.inName = inNameCheckBox.isChecked();

            if (!rule.inComment && !rule.inSubject && !rule.inName) {
                Toast.makeText(AutohideActivity.this, R.string.autohide_error_no_condition, Toast.LENGTH_LONG)
                        .show();
                return;
            }

            if (changeId == -1) {
                rulesJson.put(rule.toJson());
            } else {
                rulesJson.put(changeId, rule.toJson());
            }
            rulesChanged();
        }
    };
    AlertDialog dialog = new AlertDialog.Builder(this).setView(dialogView)
            .setTitle(changeId == -1 ? R.string.autohide_add_rule_title : R.string.autohide_edit_rule_title)
            .setPositiveButton(R.string.autohide_save_button, save)
            .setNegativeButton(android.R.string.cancel, null).create();
    dialog.setCanceledOnTouchOutside(false);
    dialog.show();
}

From source file:com.cssweb.android.base.DialogActivity.java

private void setAdapter(Spinner timeSpinner, String[] params) {
    ArrayAdapter<String> timeAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
    timeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    // Log.i("=================", ">>>>>>>>>>>>>>>>>>>>>>>>"+params);
    for (String param : params) {
        timeAdapter.add(param);//w w w. j av a  2s .  com
    }
    timeSpinner.setAdapter(timeAdapter);
}

From source file:com.flowzr.activity.RecurActivity.java

private void addSpinnerItems(Spinner spinner, LocalizableEnum[] a) {
    int length = a.length;
    SpinnerItem[] items = new SpinnerItem[length];
    for (int i = 0; i < length; i++) {
        LocalizableEnum x = a[i];//from   w ww  . ja v a  2 s  .  co  m
        String title = getString(x.getTitleId());
        String value = x.name();
        items[i] = new SpinnerItem(title, value);
    }
    ArrayAdapter<SpinnerItem> adapter = new ArrayAdapter<SpinnerItem>(this,
            android.R.layout.simple_spinner_item, items);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
}

From source file:com.google.firebase.samples.apps.mlkit.java.LivePreviewActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d(TAG, "onCreate");

    setContentView(R.layout.activity_live_preview);

    preview = (CameraSourcePreview) findViewById(R.id.firePreview);
    if (preview == null) {
        Log.d(TAG, "Preview is null");
    }/*from w w  w . ja va 2s  .  c o m*/
    graphicOverlay = (GraphicOverlay) findViewById(R.id.fireFaceOverlay);
    if (graphicOverlay == null) {
        Log.d(TAG, "graphicOverlay is null");
    }

    Spinner spinner = (Spinner) findViewById(R.id.spinner);
    List<String> options = new ArrayList<>();
    options.add(FACE_CONTOUR);
    options.add(FACE_DETECTION);
    options.add(TEXT_DETECTION);
    options.add(BARCODE_DETECTION);
    options.add(IMAGE_LABEL_DETECTION);
    options.add(CLASSIFICATION_QUANT);
    options.add(CLASSIFICATION_FLOAT);
    // Creating adapter for spinner
    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, R.layout.spinner_style, options);
    // Drop down layout style - list view with radio button
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    // attaching data adapter to spinner
    spinner.setAdapter(dataAdapter);
    spinner.setOnItemSelectedListener(this);

    ToggleButton facingSwitch = (ToggleButton) findViewById(R.id.facingSwitch);
    facingSwitch.setOnCheckedChangeListener(this);
    // Hide the toggle button if there is only 1 camera
    if (Camera.getNumberOfCameras() == 1) {
        facingSwitch.setVisibility(View.GONE);
    }

    if (allPermissionsGranted()) {
        createCameraSource(selectedModel);
    } else {
        getRuntimePermissions();
    }
}