Example usage for android.widget Spinner setSelection

List of usage examples for android.widget Spinner setSelection

Introduction

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

Prototype

@Override
    public void setSelection(int position) 

Source Link

Usage

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

private void setRecyclerViewAdapter() {
    sharesList = databaseHandler.getShares();
    final List<Purchase> salesList = databaseHandler.getSales();

    PurchaseShareAdapter purchaseAdapter = new PurchaseShareAdapter(getContext(), salesList);
    purchaseAdapter.setOnItemClickListener(new PurchaseShareAdapter.OnItemClickListener() {
        @Override/*www  . j  a  va2 s. co  m*/
        public void onItemClick(View itemView, int position) {
            final Purchase purchase = salesList.get(position);

            final Dialog dialog = new Dialog(getActivity());
            dialog.setTitle("Edit Share Sale");
            dialog.setContentView(R.layout.dialog_sell_share_holdings);
            dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
                    WindowManager.LayoutParams.WRAP_CONTENT);
            dialog.show();

            final Spinner spinner = (Spinner) dialog.findViewById(R.id.existing_spinner);
            ArrayList<String> shares = new ArrayList<>();
            int pos = 0;
            for (int i = 0; i < sharesList.size(); i++) {
                shares.add(sharesList.get(i).getName());
                if (sharesList.get(i).getName().equals(purchase.getName()))
                    pos = i;
            }
            ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(getActivity(),
                    android.R.layout.simple_spinner_item, shares);
            spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            spinner.setAdapter(spinnerAdapter);
            spinner.setSelection(pos);
            spinner.setVisibility(View.VISIBLE);

            final EditText quantity = (EditText) dialog.findViewById(R.id.no_of_shares);
            final EditText price = (EditText) dialog.findViewById(R.id.selling_price);
            quantity.setText(String.valueOf(purchase.getQuantity()));
            price.setText(String.valueOf(purchase.getPrice()));

            Calendar calendar = Calendar.getInstance();
            calendar.setTime(purchase.getDate());
            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(SalesShareFragment.this);

            Button sellShareBtn = (Button) dialog.findViewById(R.id.sell_share_btn);
            sellShareBtn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Purchase p = new Purchase();
                    p.setId(purchase.getId());

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

                    try {
                        p.setQuantity(Integer.parseInt(quantity.getText().toString()));
                    } catch (Exception e) {
                        Toast.makeText(getActivity(), "Invalid Number of Shares", Toast.LENGTH_SHORT).show();
                        return;
                    }

                    try {
                        p.setPrice(Double.parseDouble(price.getText().toString()));
                    } catch (Exception e) {
                        Toast.makeText(getActivity(), "Invalid Buying Price", Toast.LENGTH_SHORT).show();
                        return;
                    }

                    p.setType("sell");
                    p.setName(spinner.getSelectedItem().toString());
                    databaseHandler.updatePurchase(p);
                    setRecyclerViewAdapter();
                    dialog.dismiss();
                }
            });
        }
    });
    salesRecyclerView.setHasFixedSize(true);
    salesRecyclerView.setAdapter(purchaseAdapter);
    salesRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
}

From source file:org.thialfihar.android.apg.ui.dialog.CreateKeyDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final FragmentActivity context = getActivity();
    final LayoutInflater mInflater;

    final int childCount = getArguments().getInt(ARG_EDITOR_CHILD_COUNT);
    mInflater = context.getLayoutInflater();

    AlertDialog.Builder dialog = new AlertDialog.Builder(context);

    View view = mInflater.inflate(R.layout.create_key_dialog, null);
    dialog.setView(view);// w  ww  . j  av  a 2s.c  o  m
    dialog.setTitle(R.string.title_create_key);

    boolean wouldBeMasterKey = (childCount == 0);

    final Spinner algorithm = (Spinner) view.findViewById(R.id.create_key_algorithm);
    ArrayList<Choice> choices = new ArrayList<Choice>();
    choices.add(new Choice(Id.choice.algorithm.dsa, getResources().getString(R.string.dsa)));
    if (!wouldBeMasterKey) {
        choices.add(new Choice(Id.choice.algorithm.elgamal, getResources().getString(R.string.elgamal)));
    }

    choices.add(new Choice(Id.choice.algorithm.rsa, getResources().getString(R.string.rsa)));

    ArrayAdapter<Choice> adapter = new ArrayAdapter<Choice>(context, android.R.layout.simple_spinner_item,
            choices);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    algorithm.setAdapter(adapter);
    // make RSA the default
    for (int i = 0; i < choices.size(); ++i) {
        if (choices.get(i).getId() == Id.choice.algorithm.rsa) {
            algorithm.setSelection(i);
            break;
        }
    }

    final Spinner keySize = (Spinner) view.findViewById(R.id.create_key_size);
    ArrayAdapter<CharSequence> keySizeAdapter = ArrayAdapter.createFromResource(context,
            R.array.key_size_spinner_values, android.R.layout.simple_spinner_item);
    keySizeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    keySize.setAdapter(keySizeAdapter);
    keySize.setSelection(3); // Default to 4096 for the key length
    dialog.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface di, int id) {
            di.dismiss();
            try {
                int nKeyIndex = keySize.getSelectedItemPosition();
                switch (nKeyIndex) {
                case 0:
                    mNewKeySize = 512;
                    break;
                case 1:
                    mNewKeySize = 1024;
                    break;
                case 2:
                    mNewKeySize = 2048;
                    break;
                case 3:
                    mNewKeySize = 4096;
                    break;
                }
            } catch (NumberFormatException e) {
                mNewKeySize = 0;
            }

            mNewKeyAlgorithmChoice = (Choice) algorithm.getSelectedItem();
            mAlgorithmSelectedListener.onAlgorithmSelected(mNewKeyAlgorithmChoice, mNewKeySize);
        }
    });

    dialog.setCancelable(true);
    dialog.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface di, int id) {
            di.dismiss();
        }
    });

    return dialog.create();
}

From source file:com.quaap.audiometer.MainActivity.java

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

    pref = getApplicationContext().getSharedPreferences("main", MODE_PRIVATE);
    mMeterView = (MeterView) findViewById(R.id.meterLayout);

    mMicLevelReader = new MicLevelReader(this, LevelMethod.dBFS);

    ImageButton show_ctrls = (ImageButton) findViewById(R.id.show_ctrls);
    show_ctrls.setOnClickListener(new View.OnClickListener() {
        @Override/* w w w.j  a va 2s  .  co m*/
        public void onClick(View view) {
            ViewSwitcher ctrls = (ViewSwitcher) findViewById(R.id.ctrls);
            ctrls.showNext();
        }
    });
    ImageButton hide_ctrls = (ImageButton) findViewById(R.id.hide_ctrls);
    hide_ctrls.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            ViewSwitcher ctrls = (ViewSwitcher) findViewById(R.id.ctrls);
            ctrls.showPrevious();
        }
    });

    final SeekBar scaleCtrl = (SeekBar) findViewById(R.id.scaleCtrl);

    scaleCtrl.setProgress(pref.getInt("scaleCtrl", scaleCtrl.getProgress()));

    setScale();

    scaleCtrl.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
            setScale();
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });

    final ToggleButton onoff = (ToggleButton) findViewById(R.id.toggleButton);

    onoff.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (onoff.isChecked()) {
                if (!startit()) {
                    onoff.setChecked(false);
                }
            } else {
                stopit();
            }
        }
    });

    LevelMethod levM = LevelMethod.valueOf(pref.getString("levelMethod", LevelMethod.dBFS.toString()));

    final Spinner levelType = (Spinner) findViewById(R.id.levelType);
    ArrayAdapter<LevelMethod> levelTypeAdapter = new ArrayAdapter<>(this,
            android.R.layout.simple_spinner_dropdown_item, LevelMethod.values());
    levelType.setAdapter(levelTypeAdapter);

    levelType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            LevelMethod lmeth = (LevelMethod) adapterView.getSelectedItem();
            levelMethodChanged(lmeth);

        }

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

        }
    });

    levelType.setSelection(levelTypeAdapter.getPosition(levM));

    levelMethodChanged((LevelMethod) levelType.getSelectedItem());
    checkMicrophoneAccess();
}

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 ww  . j  av  a2 s  .c om
        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:com.akhbulatov.wordkeeper.ui.activity.MainActivity.java

private void showWordEditorDialog(@StringRes int titleId, @StringRes int positiveTextId,
        @StringRes int negativeTextId) {
    DialogFragment dialog = WordEditorDialog.newInstance(titleId, positiveTextId, negativeTextId);
    dialog.show(getSupportFragmentManager(), null);
    // NOTE! If the method is not called, the app crashes
    getSupportFragmentManager().executePendingTransactions();

    Dialog dialogView = dialog.getDialog();
    Spinner spinnerCategories = dialogView.findViewById(R.id.spinner_categories);

    ArrayAdapter<CharSequence> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item,
            mWordListFragment.getCategories());
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinnerCategories.setAdapter(adapter);

    // Receives and shows data of the selected word to edit in the dialog
    // Data is the name, translation and category
    if (positiveTextId == R.string.word_editor_action_edit) {
        EditText editName = dialogView.findViewById(R.id.edit_word_name);
        EditText editTranslation = dialogView.findViewById(R.id.edit_word_translation);

        editName.setText(mWordListFragment.getName());
        editTranslation.setText(mWordListFragment.getTranslation());
        spinnerCategories.setSelection(adapter.getPosition(mWordListFragment.getCategory()));
    }// w  w  w.j  a  v  a2s .  com
}

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

private void setRecyclerViewAdapter() {
    sharesList = databaseHandler.getShares();
    purchaseList = databaseHandler.getPurchases();

    if (sharesList.size() < 1) {
        emptyTV.setVisibility(View.VISIBLE);
        arrow.setVisibility(View.VISIBLE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            if (getResources().getConfiguration().orientation == 1) {
                arrow.setBackground(getResources().getDrawable(R.drawable.curved_line_vertical));
            } else {
                arrow.setBackground((getResources().getDrawable(R.drawable.curved_line_horizontal)));
            }//from  ww w.jav  a 2  s. c om
        }
    } else {
        emptyTV.setVisibility(View.GONE);
        arrow.setVisibility(View.GONE);
    }

    PurchaseShareAdapter purchaseAdapter = new PurchaseShareAdapter(getContext(), purchaseList);
    purchaseAdapter.setOnItemClickListener(new PurchaseShareAdapter.OnItemClickListener() {
        @Override
        public void onItemClick(View itemView, int position) {
            final Purchase purchase = purchaseList.get(position);

            final Dialog dialog = new Dialog(getContext());
            dialog.setTitle("Edit Share Purchase");
            dialog.setContentView(R.layout.dialog_add_share_purchase);
            dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
                    WindowManager.LayoutParams.WRAP_CONTENT);
            dialog.show();

            RadioButton newRB = (RadioButton) dialog.findViewById(R.id.radioBtn_new);
            RadioButton existingRB = (RadioButton) dialog.findViewById(R.id.radioBtn_existing);
            AutoCompleteTextView name = (AutoCompleteTextView) dialog.findViewById(R.id.share_name);
            newRB.setVisibility(View.GONE);
            existingRB.setChecked(true);
            name.setVisibility(View.GONE);

            final Spinner spinner = (Spinner) dialog.findViewById(R.id.existing_spinner);
            ArrayList<String> shares = new ArrayList<>();
            int pos = 0;
            for (int i = 0; i < sharesList.size(); i++) {
                shares.add(sharesList.get(i).getName());
                if (sharesList.get(i).getName().equals(purchase.getName()))
                    pos = i;
            }
            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);
            spinner.setSelection(pos);
            spinner.setVisibility(View.VISIBLE);

            final EditText quantity = (EditText) dialog.findViewById(R.id.no_of_shares);
            final EditText price = (EditText) dialog.findViewById(R.id.buying_price);
            quantity.setText(String.valueOf(purchase.getQuantity()));
            price.setText(String.valueOf(purchase.getPrice()));

            Calendar calendar = Calendar.getInstance();
            calendar.setTime(purchase.getDate());
            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(PurchaseShareFragment.this);

            Button addPurchaseBtn = (Button) dialog.findViewById(R.id.add_purchase_btn);
            addPurchaseBtn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Purchase p = new Purchase();
                    p.setId(purchase.getId());

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

                    try {
                        p.setQuantity(Integer.parseInt(quantity.getText().toString()));
                    } catch (Exception e) {
                        Toast.makeText(getActivity(), "Invalid Number of Shares", Toast.LENGTH_SHORT).show();
                        return;
                    }

                    try {
                        p.setPrice(Double.parseDouble(price.getText().toString()));
                    } catch (Exception e) {
                        Toast.makeText(getActivity(), "Invalid Buying Price", Toast.LENGTH_SHORT).show();
                        return;
                    }

                    p.setType("buy");
                    p.setName(spinner.getSelectedItem().toString());
                    databaseHandler.updatePurchase(p);
                    setRecyclerViewAdapter();
                    dialog.dismiss();
                }
            });
        }
    });
    sharePurchasesRecyclerView.setHasFixedSize(true);
    sharePurchasesRecyclerView.setAdapter(purchaseAdapter);
    sharePurchasesRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
}

From source file:org.mythdroid.fragments.RecEditFragment.java

private void setViews() {

    ((TextView) view.findViewById(R.id.title)).setText(prog.Title);
    ((TextView) view.findViewById(R.id.subtitle)).setText(prog.SubTitle);
    ((TextView) view.findViewById(R.id.channel)).setText(prog.Channel);
    ((TextView) view.findViewById(R.id.start)).setText(prog.startString());

    final Spinner typeSpinner = ((Spinner) view.findViewById(R.id.type));
    final ArrayAdapter<String> typeAdapter = new ArrayAdapter<String>(activity,
            android.R.layout.simple_spinner_item);
    typeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    for (RecType type : RecType.values()) {
        if (type == RecType.DONT || type == RecType.OVERRIDE)
            continue;
        typeAdapter.add(type.msg());/*from  ww w . j  a  v  a  2  s . co  m*/
    }

    typeSpinner.setAdapter(typeAdapter);
    typeSpinner.setSelection(type.ordinal());
    typeSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
            type = RecType.values()[pos];
            if (type != prog.Type || prio != prog.RecPrio)
                modified = true;
            else
                modified = false;
            updateSaveEnabled();

            if (type == RecType.NOT) {
                prioSpinner.setEnabled(false);
                if (!inlineOpts) {
                    schedOptions.setEnabled(false);
                    groupOptions.setEnabled(false);
                } else {
                    resf.setEnabled(false);
                    regf.setEnabled(false);
                }
            } else {
                prioSpinner.setEnabled(true);
                if (!inlineOpts) {
                    schedOptions.setEnabled(true);
                    groupOptions.setEnabled(true);
                } else {
                    resf.setEnabled(true);
                    regf.setEnabled(true);
                }
            }
        }

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

    });

    prioSpinner = ((Spinner) view.findViewById(R.id.prio));

    final String[] prios = new String[21];
    for (int i = -10, j = 0; i < 11; i++)
        prios[j++] = String.valueOf(i);

    final ArrayAdapter<String> prioAdapter = new ArrayAdapter<String>(activity,
            android.R.layout.simple_spinner_item, prios);
    prioAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    prioSpinner.setAdapter(prioAdapter);
    prioSpinner.setSelection(prio + 10);
    prioSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
            prio = pos - 10;
            if (type != prog.Type || prio != prog.RecPrio)
                modified = true;
            else
                modified = false;
            updateSaveEnabled();
        }

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

    });
    prioSpinner.setEnabled(type == RecType.NOT ? false : true);

    if (!inlineOpts) {
        schedOptions = (Button) view.findViewById(R.id.schedOptions);
        schedOptions.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                getFragmentManager().beginTransaction()
                        .replace(containerId, new RecEditSchedFragment(), "RecEditSchedFragment" //$NON-NLS-1$
                ).setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE).addToBackStack(null)
                        .commitAllowingStateLoss();
            }
        });
        schedOptions.setEnabled(type == RecType.NOT ? false : true);

        groupOptions = (Button) view.findViewById(R.id.groupOptions);
        groupOptions.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                getFragmentManager().beginTransaction()
                        .replace(containerId, new RecEditGroupsFragment(), "RecEditGroupsFragment" //$NON-NLS-1$
                ).setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE).addToBackStack(null)
                        .commitAllowingStateLoss();
            }
        });
        groupOptions.setEnabled(type == RecType.NOT ? false : true);
    }

    save = (Button) view.findViewById(R.id.save);
    save.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            doSave();
        }
    });
    save.setEnabled(false);

}

From source file:org.otempo.view.StationActivity.java

/**
 * Called when the activity is first created.
 *///  w w  w.j a  v  a  2 s  .  co m
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    System.gc();
    lastUpdateFormat = new SimpleDateFormat(getString(R.string.predicted_at), Locale.getDefault());
    PeriodicWorkRequest updateWork = new PeriodicWorkRequest.Builder(UpdateWorker.class, updatePeriodMs(),
            TimeUnit.MILLISECONDS)
                    .setConstraints(new Constraints.Builder().setRequiredNetworkType(NetworkType.UNMETERED)
                            .setRequiresBatteryNotLow(true).build())
                    .build();
    // Make sure there is nothing else running at this point. Not even the widget. The attention
    // of the user is on the activity.
    WorkManager.getInstance().cancelAllWork();
    // Now start polling in the background
    WorkManager.getInstance().enqueueUniquePeriodicWork("SyncStations", ExistingPeriodicWorkPolicy.KEEP,
            updateWork);

    setContentView(R.layout.main);

    if (_favoritesDB == null) {
        _favoritesDB = new FavoritesDB(getApplicationContext());
    }
    Spinner stationSpinner = findViewById(R.id.stationSpinner);
    _stationAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item);
    initStationManager();
    fillStationAdapter();
    _stationAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    stationSpinner.setAdapter(_stationAdapter);
    if (_stationManager.getStation() != null) {
        stationSpinner.setSelection(_stationAdapter.getPosition(_stationManager.getStation()));
    }
    stationSpinner.setOnItemSelectedListener(new OnStationSelectedListener());
    PreferenceManager.getDefaultSharedPreferences(getBaseContext())
            .registerOnSharedPreferenceChangeListener(this);

    reloadPreferences();

    final Button predictionHelpButton = findViewById(R.id.predictionHelpButton);
    if (predictionHelpButton != null) { // en landscape no hay
        predictionHelpButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                showDialog(DIALOG_PREDICTION_EXPLAIN_ID);
                // Marcando la preferencia
                SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
                Editor editor = prefs.edit();
                editor.putBoolean(Preferences.PREF_PREDICTED_TIME_WHY_CLICKED, true);
                editor.commit();
            }
        });
    }

    final Button hamburgerButton = findViewById(R.id.hamburgerButton);
    final DrawerLayout drawerLayout = findViewById(R.id.drawerLayout);
    final ListView sideMenu = findViewById(R.id.sideMenu);
    if (hamburgerButton != null && drawerLayout != null && sideMenu != null) {
        hamburgerButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                drawerLayout.openDrawer(sideMenu);
            }
        });
        fillSideMenu(sideMenu, drawerLayout);
    }
}

From source file:se.toxbee.sleepfighter.activity.EditGPSFilterAreaActivity.java

/**
 * Sets up the spinner for modes.//from w  w w  .j  a v a 2 s.  c  o m
 */
private void setupModeSpinner() {
    Spinner spinner = (Spinner) this.findViewById(R.id.action_edit_gpsfilter_area_mode);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
            R.array.action_edit_gpsfilter_area_mode, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);

    spinner.setSelection(this.area.getMode() == GPSFilterMode.INCLUDE ? 0 : 1);

    spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            updateMode(position);
        }

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

From source file:org.alfresco.mobile.android.application.fragments.upload.UploadFormFragment.java

private void refreshImportFolder() {
    Spinner spinner = (Spinner) rootView.findViewById(R.id.import_folder_spinner);
    UploadFolderAdapter upLoadadapter = new UploadFolderAdapter(getActivity(), R.layout.sdk_list_row,
            IMPORT_FOLDER_LIST);// ww w .ja  v a 2 s.  com
    spinner.setAdapter(upLoadadapter);
    spinner.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
            folderImportId = (Integer) parent.getItemAtPosition(pos);
            importFolderIndex = pos;
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // DO Nothing
        }
    });
    if (folderImportId == null) {
        importFolderIndex = 0;
    }
    spinner.setSelection(importFolderIndex);
}