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:org.otempo.view.StationActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
        @NonNull int[] grantResults) {
    for (int i = 0; i < permissions.length; i++) {
        if (permissions[i].equals(android.Manifest.permission.ACCESS_COARSE_LOCATION)
                && grantResults[i] == PackageManager.PERMISSION_GRANTED) {
            Log.d("OTempo", "Got GPS permission");
            initStationManager();//  w  w w .jav  a2s  .c  o m
            if (_stationManager.getStation() != null) {
                Spinner stationSpinner = findViewById(R.id.stationSpinner);
                stationSpinner.setSelection(_stationAdapter.getPosition(_stationManager.getStation()));
            }
        } else if (permissions[i].equals(android.Manifest.permission.READ_EXTERNAL_STORAGE)
                && grantResults[i] == PackageManager.PERMISSION_GRANTED) {
            reloadPreferences();
        }
    }
}

From source file:com.prevas.redmine.NewIssueActivity.java

private void loadContents() {
    mParentId = getIntent().getIntExtra("Parent", -1);

    // Parent id if it is a subtask
    CheckBox parentIdCheckBox = (CheckBox) findViewById(R.id.check_parentId);
    parentIdCheckBox.setClickable(false);
    if (-1 != mParentId) {
        parentIdCheckBox.setChecked(true);
        parentIdCheckBox.setText("Parent #" + Integer.toString(mParentId));
    } else {// w  ww .  j a v a 2  s .c  om
        parentIdCheckBox.setChecked(false);
        //parentIdCheckBox.setClickable(false);
        parentIdCheckBox.setText("No parent");
    }

    mSubjectEditText = (EditText) findViewById(R.id.edit_Subject);
    mSubjectEditText.setHint("Enter Subject");

    mDescriptionEditText = (EditText) findViewById(R.id.edit_Description);
    //mDescriptionEditText.setHint("Enter Description");      
    mNotesEditText = (EditText) findViewById(R.id.edit_Notes);

    mEstimatedHoursEditText = (EditText) findViewById(R.id.edit_EstimatedTime);

    mStartDateTextView = (TextView) findViewById(R.id.txt_StartDateValue);

    // Trackers - Spinner
    Spinner spinTracker = (Spinner) findViewById(R.id.spin_Tracker);
    try {
        spinTracker.setAdapter(mTrackerAdapter);
    } catch (Exception e) {
        e.printStackTrace();
    }

    // Statuses - Spinner
    Spinner spinStatus = (Spinner) findViewById(R.id.spin_Status);
    try {
        spinStatus.setAdapter(mStatusAdapter);
        spinStatus.setSelection(mStatusAdapter.getItemIndexByName("New"));
    } catch (Exception e) {
        e.printStackTrace();
    }

    // Priority - Spinner
    Spinner spinPriority = (Spinner) findViewById(R.id.spin_Priority);
    try {
        spinPriority.setAdapter(mPrioritiesAdapter);
        spinPriority.setSelection(mPrioritiesAdapter.getItemIndexByName("Normal"));
    } catch (Exception e) {
        e.printStackTrace();
    }

    // Version - Spinner
    Spinner spinVersion = (Spinner) findViewById(R.id.spin_Version);
    try {
        spinVersion.setAdapter(mVersionAdapter);
    } catch (Exception e) {
        e.printStackTrace();
    }

    // Assignee
    Spinner spinMember = (Spinner) findViewById(R.id.spin_Assignee);
    try {
        spinMember.setAdapter(mAssigneeAdapter);
        //String currentUser = PrevasRedmine.m_redmineManager.getCurrentUser().toString();
        //spinMember.setSelection(mAssigneeAdapter.getPosition(currentUser));
        spinMember.setSelection(mAssigneeAdapter.getPosition("--"));
    } catch (Exception e) {
        e.printStackTrace();
    }

    mStartDateBtn = (Button) findViewById(R.id.btn_StartDateChange);
    mStartDateBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showDialog(STARTDATE_DIALOG_ID);
        }
    });
    /* get the current date */
    final Calendar startDateCal = Calendar.getInstance();
    mStartYear = startDateCal.get(Calendar.YEAR);
    mStartMonth = startDateCal.get(Calendar.MONTH);
    mStartDay = startDateCal.get(Calendar.DAY_OF_MONTH);

    mDueDateTextView = (TextView) findViewById(R.id.txt_DueDateValue);

    mDueDateBtn = (Button) findViewById(R.id.btn_DueDateChange);
    mDueDateBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showDialog(DUEDATE_DIALOG_ID);
        }
    });

    /* get the current date */
    final Calendar dueDateCal = Calendar.getInstance();
    mDueYear = dueDateCal.get(Calendar.YEAR);
    mDueMonth = dueDateCal.get(Calendar.MONTH);
    mDueDay = dueDateCal.get(Calendar.DAY_OF_MONTH);

    // Progress Contents
    mPercentDoneTextView = (TextView) findViewById(R.id.txt_Progress);
    mPercentDoneSeekbar = (SeekBar) findViewById(R.id.seekbar_PercentDone);
    try {

        mPercentDoneTextView.setText("0%");
        mPercentDoneSeekbar.setMax(0);
        mPercentDoneSeekbar.setMax(100);
        // setting to 0, there is a bug in android progress bar
        mPercentDoneSeekbar.setProgress(0);
        mPercentDoneSeekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekbar, int progress, boolean fromTouch) {
                mPercentDoneTextView.setText(Integer.toString(progress) + "%");
                mPercentDone = progress;
            }

            @Override
            public void onStartTrackingTouch(SeekBar arg0) {
            }

            @Override
            public void onStopTrackingTouch(SeekBar arg0) {

            }

        });
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:ng.uavp.ch.ngusbterminal.SettingsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    thisview = inflater.inflate(R.layout.settings, container, false);

    SharedPreferences sharedPref = getActivity().getSharedPreferences("uart_settings", Context.MODE_PRIVATE);

    UartSettings defaults = new UartSettings();

    Spinner spinner1 = (Spinner) thisview.findViewById(R.id.spinnerBaud);
    // Create an ArrayAdapter using the string array and a default spinner layout
    ArrayAdapter<CharSequence> adapter1 = ArrayAdapter.createFromResource(getActivity(), R.array.baud_array,
            R.layout.spinner_item_settings);
    // Specify the layout to use when the list of choices appears
    adapter1.setDropDownViewResource(R.layout.spinner_item_settings);
    // Apply the adapter to the spinner
    spinner1.setAdapter(adapter1);//from   w ww  . j a  v a 2  s  .  c  om
    SetSpinnerSelection(sharedPref, spinner1, "baudrate", defaults.baudrate);

    Spinner spinner2 = (Spinner) thisview.findViewById(R.id.spinnerBits);
    // Create an ArrayAdapter using the string array and a default spinner layout
    ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource(getActivity(), R.array.databits_array,
            R.layout.spinner_item_settings);
    // Specify the layout to use when the list of choices appears
    adapter2.setDropDownViewResource(R.layout.spinner_item_settings);
    // Apply the adapter to the spinner
    spinner2.setAdapter(adapter2);
    SetSpinnerSelection(sharedPref, spinner2, "databits", defaults.dataBits);

    Spinner spinner3 = (Spinner) thisview.findViewById(R.id.spinnerParity);
    // Create an ArrayAdapter using the string array and a default spinner layout
    ArrayAdapter<CharSequence> adapter3 = ArrayAdapter.createFromResource(getActivity(), R.array.parity_array,
            R.layout.spinner_item_settings);
    // Specify the layout to use when the list of choices appears
    adapter3.setDropDownViewResource(R.layout.spinner_item_settings);
    // Apply the adapter to the spinner
    spinner3.setAdapter(adapter3);
    spinner3.setSelection(sharedPref.getInt("parity", defaults.parity));

    Spinner spinner4 = (Spinner) thisview.findViewById(R.id.spinnerStopbits);
    // Create an ArrayAdapter using the string array and a default spinner layout
    ArrayAdapter<CharSequence> adapter4 = ArrayAdapter.createFromResource(getActivity(), R.array.stopbits_array,
            R.layout.spinner_item_settings);
    // Specify the layout to use when the list of choices appears
    adapter4.setDropDownViewResource(R.layout.spinner_item_settings);
    // Apply the adapter to the spinner
    spinner4.setAdapter(adapter4);
    SetSpinnerSelection(sharedPref, spinner4, "stopbits", defaults.stopBits);

    Spinner spinner5 = (Spinner) thisview.findViewById(R.id.spinnerFlow);
    // Create an ArrayAdapter using the string array and a default spinner layout
    ArrayAdapter<CharSequence> adapter5 = ArrayAdapter.createFromResource(getActivity(), R.array.flowcontrol,
            R.layout.spinner_item_settings);
    // Specify the layout to use when the list of choices appears
    adapter5.setDropDownViewResource(R.layout.spinner_item_settings);
    // Apply the adapter to the spinner
    spinner5.setAdapter(adapter5);
    spinner5.setSelection(sharedPref.getInt("flowcontrol", defaults.flowControl));

    String[] devList;
    try {
        devList = usb.createDeviceList();
        usbDevicesFound = devList.length;
    } catch (D2xxManager.D2xxException e) {
        devList = new String[1];
        devList[0] = e.getLocalizedMessage();
    }

    if (devList.length == 0) {
        devList = new String[1];
        devList[0] = getString(R.string.error_noAdapter);
    }

    Spinner spinner6 = (Spinner) thisview.findViewById(R.id.spinnerInterfce);

    ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(activity,
            R.layout.spinner_item_settings, devList);
    spinnerArrayAdapter.setDropDownViewResource(R.layout.spinner_item_settings);
    spinner6.setAdapter(spinnerArrayAdapter);

    Button button1 = (Button) thisview.findViewById(R.id.button1);
    button1.setEnabled(usbDevicesFound > 0);

    button1.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            doConnect();
        }
    });

    if (usbDevicesFound == 0)
        spinner6.setBackgroundColor(Color.MAGENTA);
    else
        spinner6.setBackgroundColor(Color.TRANSPARENT);

    return thisview;
}

From source file:org.thaliproject.nativetest.app.fragments.SettingsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_settings, container, false);

    mSettings = Settings.getInstance(view.getContext());
    mSettings.load();/* ww  w.j  a  v a  2  s  .  com*/

    mConnectionTimeoutEditText = (EditText) view.findViewById(R.id.connectionTimeoutEditText);
    mConnectionTimeoutEditText.setText(String.valueOf(mSettings.getConnectionTimeout()));
    mConnectionTimeoutEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            if (editable.length() > 0) {
                try {
                    mSettings.setConnectionTimeout(Long.parseLong(editable.toString()));
                } catch (NumberFormatException e) {
                    Log.e(TAG, e.getMessage(), e);
                    mConnectionTimeoutEditText.setText(String.valueOf(mSettings.getConnectionTimeout()));
                }
            }
        }
    });

    mPortNumberEditText = (EditText) view.findViewById(R.id.portNumberEditText);
    mPortNumberEditText.setText(String.valueOf(mSettings.getPortNumber()));
    mPortNumberEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            if (editable.length() > 0 && !editable.toString().equals("-")) {
                try {
                    mSettings.setPortNumber(Integer.parseInt(editable.toString()));
                } catch (NumberFormatException e) {
                    Log.e(TAG, e.getMessage(), e);
                    mPortNumberEditText.setText(String.valueOf(mSettings.getPortNumber()));
                }
            }
        }
    });

    mListenForIncomingConnectionsCheckbox = (CheckBox) view
            .findViewById(R.id.listenForIncomingConnectionCheckbox);
    mListenForIncomingConnectionsCheckbox.setChecked(mSettings.getListenForIncomingConnections());
    mListenForIncomingConnectionsCheckbox
            .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                    mSettings.setListenForIncomingConnections(b);
                }
            });

    mHandshakeRequiredCheckbox = (CheckBox) view.findViewById(R.id.handshakeRequiredCheckBox);
    mHandshakeRequiredCheckbox.setChecked(mSettings.getHandshakeRequired());
    mHandshakeRequiredCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            mSettings.setHandshakeRequired(b);
        }
    });

    mEnableWifiCheckBox = (CheckBox) view.findViewById(R.id.enableWifiCheckBox);
    mEnableWifiCheckBox.setChecked(mSettings.getEnableWifiDiscovery());
    mEnableWifiCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            mSettings.setEnableWifiDiscovery(b);
        }
    });

    mEnableBleCheckBox = (CheckBox) view.findViewById(R.id.enableBleCheckBox);
    mEnableBleCheckBox.setChecked(mSettings.getEnableBleDiscovery());
    mEnableBleCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            mSettings.setEnableBleDiscovery(b);
        }
    });

    Spinner spinner = (Spinner) view.findViewById(R.id.advertiseModeSpinner);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(view.getContext(),
            R.array.advertise_mode_string_array, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    spinner.setSelection(mSettings.getAdvertiseMode());
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int index, long l) {
            mSettings.setAdvertiseMode(index);
        }

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

    spinner = (Spinner) view.findViewById(R.id.advertiseTxPowerLevelSpinner);
    adapter = ArrayAdapter.createFromResource(view.getContext(), R.array.advertise_tx_power_level_string_array,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    spinner.setSelection(mSettings.getAdvertiseTxPowerLevel());
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int index, long l) {
            mSettings.setAdvertiseTxPowerLevel(index);
        }

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

    spinner = (Spinner) view.findViewById(R.id.scanModeSpinner);
    adapter = ArrayAdapter.createFromResource(view.getContext(), R.array.scan_mode_string_array,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    spinner.setSelection(mSettings.getScanMode());
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int index, long l) {
            mSettings.setScanMode(index);
        }

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

    mBufferSizeEditText = (EditText) view.findViewById(R.id.bufferSizeEditText);
    mBufferSizeEditText.setText(String.valueOf(mSettings.getBufferSize()));
    mBufferSizeEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            if (editable.length() > 0) {
                try {
                    mSettings.setBufferSize(Integer.parseInt(editable.toString()));
                } catch (NumberFormatException e) {
                    Log.e(TAG, e.getMessage(), e);
                    mBufferSizeEditText.setText(String.valueOf(mSettings.getBufferSize()));
                }
            }
        }
    });

    mDataAmountEditText = (EditText) view.findViewById(R.id.dataAmountEditText);
    mDataAmountEditText.setText(String.valueOf(mSettings.getDataAmount()));
    mDataAmountEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            if (editable.length() > 0) {
                try {
                    mSettings.setDataAmount(Long.parseLong(editable.toString()));
                } catch (NumberFormatException e) {
                    Log.e(TAG, e.getMessage(), e);
                    mDataAmountEditText.setText(String.valueOf(mSettings.getDataAmount()));
                }
            }
        }
    });

    mEnableAutoConnectCheckBox = (CheckBox) view.findViewById(R.id.autoConnectCheckBox);
    mEnableAutoConnectCheckBox.setChecked(mSettings.getAutoConnect());
    mEnableAutoConnectCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            mSettings.setAutoConnect(b);
        }
    });

    mEnableAutoConnectEvenWhenIncomingConnectionEstablishedCheckBox = (CheckBox) view
            .findViewById(R.id.autoConnectEvenWhenIncomingCheckBox);
    mEnableAutoConnectEvenWhenIncomingConnectionEstablishedCheckBox
            .setChecked(mSettings.getAutoConnectEvenWhenIncomingConnectionEstablished());
    mEnableAutoConnectEvenWhenIncomingConnectionEstablishedCheckBox
            .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                    mSettings.setAutoConnectEvenWhenIncomingConnectionEstablished(b);
                }
            });

    return view;
}

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

/**
 * Recarga las preferencias, por si han cambiado
 *///  ww  w .jav a2  s .co  m
private void reloadPreferences() {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    String stationOrdering = prefs.getString(Preferences.PREF_STATION_ORDERING,
            Preferences.DEFAULT_STATION_ORDERING);
    if (stationOrdering.equals("favorites")) {
        Station.sortStations(new FavoritesStationComparator());
    } else if (stationOrdering.equals("alphabetic")) {
        Station.sortStations(new AlphabeticStationComparator());
    }
    _stationManager.setAutoSortStations(stationOrdering.equals("distance"));
    fillStationAdapter();
    Spinner stationSpinner = findViewById(R.id.stationSpinner);
    stationSpinner.setSelection(_stationAdapter.getPosition(_stationManager.getStation()));
    String background = prefs.getString(Preferences.PREF_BACKGROUND, "default");
    boolean mustUpdate = !_background.equals(background);
    _background = background;
    if (_background.equals("black")) {
        findViewById(R.id.scrollView).setBackgroundColor(Color.BLACK);
    } else if (_background.equals("default")) {
        if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
            findViewById(R.id.scrollView).setBackgroundResource(R.drawable.background_land);
        } else {
            findViewById(R.id.scrollView).setBackgroundResource(R.drawable.background);
        }
    } else if (_background.equals("user_image")) {
        maybeRequestStoragePermission();
        String fileName = prefs.getString(Preferences.PREF_BACKGROUND_USER_IMAGE, "");
        // No permitimos imgenes de ms de 1000 pixeles de ancho o alto, para no petar la memoria con esta imagen
        int maxW = Math.max((int) (getResources().getDisplayMetrics().widthPixels * 1.5), 1000);
        int maxH = Math.max((int) (getResources().getDisplayMetrics().heightPixels * 1.5), 1000);
        Bitmap bitmap = BitmapUtils.safeDecodeFile(new File(fileName), maxW, maxH);
        if (bitmap != null) {
            BitmapDrawable image = new BitmapDrawable(getResources(), bitmap);
            findViewById(R.id.scrollView).setBackground(image);
        }
    }
    if (mustUpdate) {
        updateLayout();
    }
    boolean predictedTimeWhyClicked = prefs.getBoolean(Preferences.PREF_PREDICTED_TIME_WHY_CLICKED, false);
    if (predictedTimeWhyClicked) {
        View predButton = findViewById(R.id.predictionHelpButton);
        if (predButton != null) {
            predButton.setVisibility(View.GONE);
        }
    }
}

From source file:com.mbientlab.metawear.app.popup.AccelerometerSettings.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    getDialog().setTitle("Accelerometer Settings");

    Spinner spinnerObj;

    spinnerObj = (Spinner) view.findViewById(R.id.spinner1);
    spinnerObj.setAdapter(new ArrayAdapter<TapType>(getActivity(), R.layout.command_row, R.id.command_name,
            TapType.values()));//from w w  w  .j  a  va 2  s. com
    spinnerObj.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            accelConfig.modifyTapType(position);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    spinnerObj.setSelection(accelConfig.tapTypePos());

    spinnerObj = (Spinner) view.findViewById(R.id.spinner2);
    spinnerObj.setAdapter(
            new ArrayAdapter<Axis>(getActivity(), R.layout.command_row, R.id.command_name, Axis.values()));
    spinnerObj.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            accelConfig.modifyTapAxis(position);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    spinnerObj.setSelection(accelConfig.tapAxisPos());

    spinnerObj = (Spinner) view.findViewById(R.id.spinner3);
    spinnerObj.setAdapter(
            new ArrayAdapter<Axis>(getActivity(), R.layout.command_row, R.id.command_name, Axis.values()));
    spinnerObj.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            accelConfig.modifyShakeAxis(position);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    spinnerObj.setSelection(accelConfig.shakeAxisPos());

    spinnerObj = (Spinner) view.findViewById(R.id.spinner4);
    spinnerObj.setAdapter(new ArrayAdapter<FullScaleRange>(getActivity(), R.layout.command_row,
            R.id.command_name, FullScaleRange.values()));
    spinnerObj.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            accelConfig.modifyDataRange(position);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    spinnerObj.setSelection(accelConfig.fsrPos());

    spinnerObj = (Spinner) view.findViewById(R.id.spinner5);
    spinnerObj.setAdapter(new ArrayAdapter<OutputDataRate>(getActivity(), R.layout.command_row,
            R.id.command_name, OutputDataRate.values()));
    spinnerObj.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            accelConfig.modifySamplingRate(position);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    spinnerObj.setSelection(accelConfig.odrPos());

    spinnerObj = (Spinner) view.findViewById(R.id.spinner6);
    spinnerObj.setAdapter(new ArrayAdapter<String>(getActivity(), R.layout.command_row, R.id.command_name,
            new String[] { "Free Fall", "Motion" }));
    spinnerObj.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            accelConfig.modifyMovementType(position);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    spinnerObj.setSelection(accelConfig.movementPos());

    spinnerObj = (Spinner) view.findViewById(R.id.spinner7);
    spinnerObj.setAdapter(ArrayAdapter.createFromResource(getActivity(), R.array.firmware_version_array,
            android.R.layout.simple_spinner_item));
    spinnerObj.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            accelConfig.modifyFirmwareVersion(position);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    spinnerObj.setSelection(accelConfig.firmwarePos());
}

From source file:org.lyricue.android.BibleFragment.java

void select_verse(String verse) {
    Log.i(TAG, "Select Verse " + verse);
    Spinner spin = (Spinner) v.findViewById(R.id.spinBibleBook);
    String[] tokens = verse.split("[-:]");
    String bible = tokens[0];//from  w  ww.ja  v a 2 s .  c o  m
    int chapter = Integer.parseInt(tokens[1]);
    int start_verse = Integer.parseInt(tokens[2]);
    int end_verse = Integer.parseInt(tokens[4]);
    for (int i = 0; i < spin.getCount(); i++) {
        if (spin.getItemAtPosition(i).toString().equals(bible)) {
            spin.setSelection(i);
        }
    }
    spin = (Spinner) v.findViewById(R.id.spinBibleChapter);
    spin.setSelection(chapter - 1);
    spin = (Spinner) v.findViewById(R.id.spinBibleVerseStart);
    spin.setSelection(start_verse - 1);
    spin = (Spinner) v.findViewById(R.id.spinBibleVerseEnd);
    spin.setSelection(end_verse - 1);
}

From source file:com.teddoll.movies.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    final MenuItem sort = menu.findItem(R.id.menu_list_select);
    Spinner spinner = (Spinner) MenuItemCompat.getActionView(sort);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.sort_array,
            R.layout.item_action_bar_spinner);
    adapter.setDropDownViewResource(R.layout.item_action_bar_spinner_item);
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override//from   w ww. j  a  v a 2s  .  c  o m
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            sort(position);
        }

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

        }
    });
    spinner.setAdapter(adapter);
    spinner.setSelection(this.sort.ordinal());
    return true;
}

From source file:com.kunze.androidlocaltodo.TaskActivityFragment.java

private void InitializeViewFields(View rootView, Task task) {
    final EditText nameEdit = (EditText) rootView.findViewById(R.id.task_name_edit);
    final TextView nameStatic = (TextView) rootView.findViewById(R.id.task_name_static);
    nameStatic.setText(task.mName);/* ww  w.  j av a2 s  .com*/
    nameEdit.setText(task.mName);
    final TextView descriptionEdit = (TextView) rootView.findViewById(R.id.task_description_edit);
    descriptionEdit.setText(task.mDescription);
    final TextView dueDateView = (TextView) rootView.findViewById(R.id.due_date_text);
    SetFriendlyDueDateText(dueDateView, task.mDueDate);
    final Calendar dueDate = task.mDueDate;
    final DatePicker datePicker = (DatePicker) rootView.findViewById(R.id.due_date_calendar);
    datePicker.updateDate(dueDate.get(Calendar.YEAR), dueDate.get(Calendar.MONTH),
            dueDate.get(Calendar.DAY_OF_MONTH));
    final CheckBox repeatCheck = (CheckBox) rootView.findViewById(R.id.repeat);
    Boolean repeat = task.mRepeatUnit != Task.RepeatUnit.NONE;
    repeatCheck.setChecked(repeat);
    SetRepeatVisibility(rootView, repeat);
    final EditText repeatTimeEdit = (EditText) rootView.findViewById(R.id.repeat_time);
    repeatTimeEdit.setText(Integer.toString(task.mRepeatTime));
    final Spinner repeatUnitSpinner = (Spinner) rootView.findViewById(R.id.repeat_unit);
    int repeatUnitPos = 0;
    switch (task.mRepeatUnit) {
    case DAYS:
        repeatUnitPos = 0;
        break;
    case WEEKS:
        repeatUnitPos = 1;
        break;
    case MONTHS:
        repeatUnitPos = 2;
        break;
    case YEARS:
        repeatUnitPos = 3;
        break;
    case NONE:
        repeatUnitPos = 0;
    }
    repeatUnitSpinner.setSelection(repeatUnitPos);
    final RadioButton repeatFromComplete = (RadioButton) rootView.findViewById(R.id.repeat_from_complete);
    final RadioButton repeatFromDue = (RadioButton) rootView.findViewById(R.id.repeat_from_due);
    if (task.mRepeatFromComplete) {
        repeatFromComplete.setChecked(true);
    } else {
        repeatFromDue.setChecked(true);
    }
}

From source file:com.gsma.rcs.provisioning.local.StackProvisioning.java

@Override
public void displayRcsSettings() {
    if (sLogger.isActivated()) {
        sLogger.debug("displayRcsSettings");
    }/*from   ww  w.  j  a v a 2s  . com*/
    Context ctx = getContext();
    Spinner spinner = (Spinner) mRootView.findViewById(R.id.Autoconfig);
    ArrayAdapter<String> adapter = new ArrayAdapter<>(ctx, android.R.layout.simple_spinner_item, mConfigModes);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    ConfigurationMode mode = sRcsSettings.getConfigurationMode();
    spinner.setSelection(ConfigurationMode.AUTO.equals(mode) ? 1 : 0);

    TextView textView = (TextView) mRootView.findViewById(R.id.client_vendor);
    textView.setText(Build.MANUFACTURER);

    spinner = (Spinner) mRootView.findViewById(R.id.EnableRcsSwitch);
    adapter = new ArrayAdapter<>(ctx, android.R.layout.simple_spinner_item, mEnableRcseSwitch);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    EnableRcseSwitch rcsSwitch = sRcsSettings.getEnableRcseSwitch();
    switch (rcsSwitch) {
    case ALWAYS_SHOW:
    case ONLY_SHOW_IN_ROAMING:
        spinner.setSelection(rcsSwitch.toInt());
        break;
    default:
        spinner.setSelection(2);
    }
    mHelper.setStringEditText(R.id.SecondaryProvisioningAddress,
            RcsSettingsData.SECONDARY_PROVISIONING_ADDRESS);
    mHelper.setBoolCheckBox(R.id.SecondaryProvisioningAddressOnly,
            RcsSettingsData.SECONDARY_PROVISIONING_ADDRESS_ONLY);

    spinner = (Spinner) mRootView.findViewById(R.id.NetworkAccess);
    adapter = new ArrayAdapter<>(ctx, android.R.layout.simple_spinner_item, mNetworkAccesses);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    NetworkAccessType access = sRcsSettings.getNetworkAccess();
    switch (access) {
    case MOBILE:
        spinner.setSelection(1);
        break;
    case WIFI:
        spinner.setSelection(2);
        break;
    case ANY:
    default:
        spinner.setSelection(0);
    }
    spinner = (Spinner) mRootView.findViewById(R.id.SipDefaultProtocolForMobile);
    adapter = new ArrayAdapter<>(ctx, android.R.layout.simple_spinner_item, SIP_PROTOCOL);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    String sipMobile = sRcsSettings.getSipDefaultProtocolForMobile();
    if (SIP_PROTOCOL[0].equalsIgnoreCase(sipMobile)) {
        spinner.setSelection(0);
    } else if (SIP_PROTOCOL[1].equalsIgnoreCase(sipMobile)) {
        spinner.setSelection(1);
    } else {
        spinner.setSelection(2);
    }
    spinner = (Spinner) mRootView.findViewById(R.id.SipDefaultProtocolForWifi);
    adapter = new ArrayAdapter<>(ctx, android.R.layout.simple_spinner_item, SIP_PROTOCOL);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    String sipWifi = sRcsSettings.getSipDefaultProtocolForWifi();
    if (SIP_PROTOCOL[0].equalsIgnoreCase(sipWifi)) {
        spinner.setSelection(0);
    } else if (SIP_PROTOCOL[1].equalsIgnoreCase(sipWifi)) {
        spinner.setSelection(1);
    } else {
        spinner.setSelection(2);
    }
    String[] certificates = loadCertificatesList();
    spinner = (Spinner) mRootView.findViewById(R.id.TlsCertificateRoot);
    adapter = new ArrayAdapter<>(ctx, android.R.layout.simple_spinner_item, certificates);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    boolean found = false;
    String certRoot = sRcsSettings.getTlsCertificateRoot();
    for (int i = 0; i < certificates.length; i++) {
        if (certRoot != null && certRoot.contains(certificates[i])) {
            spinner.setSelection(i);
            found = true;
        }
    }
    if (!found) {
        spinner.setSelection(0);
        sRcsSettings.writeString(RcsSettingsData.TLS_CERTIFICATE_ROOT, "");
    }
    spinner = (Spinner) mRootView.findViewById(R.id.TlsCertificateIntermediate);
    adapter = new ArrayAdapter<>(ctx, android.R.layout.simple_spinner_item, certificates);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    spinner.setSelection(0);
    found = false;
    String certInt = sRcsSettings.getTlsCertificateIntermediate();
    for (int i = 0; i < certificates.length; i++) {
        if (certInt != null && certInt.contains(certificates[i])) {
            spinner.setSelection(i);
            found = true;
        }
    }
    if (!found) {
        spinner.setSelection(0);
        sRcsSettings.writeString(RcsSettingsData.TLS_CERTIFICATE_INTERMEDIATE, "");
    }
    spinner = (Spinner) mRootView.findViewById(R.id.FtProtocol);
    adapter = new ArrayAdapter<>(ctx, android.R.layout.simple_spinner_item, FT_PROTOCOL);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    FileTransferProtocol ftProtocol = sRcsSettings.getFtProtocol();
    if (FileTransferProtocol.HTTP.equals(ftProtocol)) {
        spinner.setSelection(0);
    } else {
        spinner.setSelection(1);
    }
    mHelper.setLongEditText(R.id.ImsServicePollingPeriod, RcsSettingsData.IMS_SERVICE_POLLING_PERIOD);
    mHelper.setIntEditText(R.id.SipListeningPort, RcsSettingsData.SIP_DEFAULT_PORT);
    mHelper.setLongEditText(R.id.SipTimerT1, RcsSettingsData.SIP_TIMER_T1);
    mHelper.setLongEditText(R.id.SipTimerT2, RcsSettingsData.SIP_TIMER_T2);
    mHelper.setLongEditText(R.id.SipTimerT4, RcsSettingsData.SIP_TIMER_T4);
    mHelper.setLongEditText(R.id.SipTransactionTimeout, RcsSettingsData.SIP_TRANSACTION_TIMEOUT);
    mHelper.setLongEditText(R.id.SipKeepAlivePeriod, RcsSettingsData.SIP_KEEP_ALIVE_PERIOD);
    mHelper.setIntEditText(R.id.DefaultMsrpPort, RcsSettingsData.MSRP_DEFAULT_PORT);
    mHelper.setIntEditText(R.id.DefaultRtpPort, RcsSettingsData.RTP_DEFAULT_PORT);
    mHelper.setLongEditText(R.id.MsrpTransactionTimeout, RcsSettingsData.MSRP_TRANSACTION_TIMEOUT);
    mHelper.setLongEditText(R.id.RegisterExpirePeriod, RcsSettingsData.REGISTER_EXPIRE_PERIOD);
    mHelper.setLongEditText(R.id.RegisterRetryBaseTime, RcsSettingsData.REGISTER_RETRY_BASE_TIME);
    mHelper.setLongEditText(R.id.RegisterRetryMaxTime, RcsSettingsData.REGISTER_RETRY_MAX_TIME);
    mHelper.setLongEditText(R.id.PublishExpirePeriod, RcsSettingsData.PUBLISH_EXPIRE_PERIOD);
    mHelper.setLongEditText(R.id.RevokeTimeout, RcsSettingsData.REVOKE_TIMEOUT);
    mHelper.setLongEditText(R.id.RingingPeriod, RcsSettingsData.RINGING_SESSION_PERIOD);
    mHelper.setLongEditText(R.id.SubscribeExpirePeriod, RcsSettingsData.SUBSCRIBE_EXPIRE_PERIOD);
    mHelper.setLongEditText(R.id.IsComposingTimeout, RcsSettingsData.IS_COMPOSING_TIMEOUT);
    mHelper.setLongEditText(R.id.SessionRefreshExpirePeriod, RcsSettingsData.SESSION_REFRESH_EXPIRE_PERIOD);
    mHelper.setLongEditText(R.id.CapabilityRefreshTimeout, RcsSettingsData.CAPABILITY_REFRESH_TIMEOUT);
    mHelper.setLongEditText(R.id.CapabilityExpiryTimeout, RcsSettingsData.CAPABILITY_EXPIRY_TIMEOUT);
    mHelper.setLongEditText(R.id.CapabilityPollingPeriod, RcsSettingsData.CAPABILITY_POLLING_PERIOD);
    mHelper.setBoolCheckBox(R.id.TcpFallback, RcsSettingsData.TCP_FALLBACK);
    mHelper.setBoolCheckBox(R.id.SipKeepAlive, RcsSettingsData.SIP_KEEP_ALIVE);
    mHelper.setBoolCheckBox(R.id.PermanentState, RcsSettingsData.PERMANENT_STATE_MODE);
    mHelper.setBoolCheckBox(R.id.TelUriFormat, RcsSettingsData.TEL_URI_FORMAT);
    mHelper.setBoolCheckBox(R.id.ImAlwaysOn, RcsSettingsData.IM_CAPABILITY_ALWAYS_ON);
    mHelper.setBoolCheckBox(R.id.FtAlwaysOn, RcsSettingsData.FT_CAPABILITY_ALWAYS_ON);
    mHelper.setBoolCheckBox(R.id.FtHttpAlwaysOn, RcsSettingsData.FT_HTTP_CAP_ALWAYS_ON);
    mHelper.setBoolCheckBox(R.id.InviteOnlyGroupchatSF, RcsSettingsData.GROUP_CHAT_INVITE_ONLY_FULL_SF);
    mHelper.setBoolCheckBox(R.id.ImUseReports, RcsSettingsData.IM_USE_REPORTS);
    mHelper.setBoolCheckBox(R.id.Gruu, RcsSettingsData.GRUU);
    mHelper.setBoolCheckBox(R.id.CpuAlwaysOn, RcsSettingsData.CPU_ALWAYS_ON);
    mHelper.setBoolCheckBox(R.id.SecureMsrpOverWifi, RcsSettingsData.SECURE_MSRP_OVER_WIFI);
    mHelper.setBoolCheckBox(R.id.SecureRtpOverWifi, RcsSettingsData.SECURE_RTP_OVER_WIFI);
    mHelper.setBoolCheckBox(R.id.ImeiAsDeviceId, RcsSettingsData.USE_IMEI_AS_DEVICE_ID);
    mHelper.setBoolCheckBox(R.id.ControlExtensions, RcsSettingsData.CONTROL_EXTENSIONS);
    mHelper.setBoolCheckBox(R.id.AllowExtensions, RcsSettingsData.ALLOW_EXTENSIONS);
    mHelper.setIntEditText(R.id.MaxMsrpLengthExtensions, RcsSettingsData.MAX_MSRP_SIZE_EXTENSIONS);
    mHelper.setLongEditText(R.id.MessagingCapabilitiesValidity, RcsSettingsData.MSG_CAP_VALIDITY_PERIOD);
}