Java Code Examples for android.support.v7.widget.AppCompatSpinner#setOnItemSelectedListener()

The following examples show how to use android.support.v7.widget.AppCompatSpinner#setOnItemSelectedListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GetTableFragment.java    From EosCommander with MIT License 6 votes vote down vote up
private AppCompatSpinner setDropDownList(int dropDownListId, List<String> data, AdapterView.OnItemSelectedListener itemSelectedListener) {
    AppCompatSpinner spinner = mRootView.findViewById( dropDownListId );
    if ( spinner == null ) {
        return null;
    }

    ArrayAdapter<String> adapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, data);
    adapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item );
    spinner.setAdapter( adapter );

    if ( itemSelectedListener != null ) {
        spinner.setOnItemSelectedListener(itemSelectedListener);
    }

    return spinner;
}
 
Example 2
Source File: SettingsActivity.java    From EosCommander with MIT License 6 votes vote down vote up
private AppCompatSpinner addSpinnerData(int spinnerViewId, List<String> list, int curPosition,
                                        AdapterView.OnItemSelectedListener itemSelectedListener) {
    if ( list == null ) return null;

    ArrayAdapter<String> adapter = new ArrayAdapter<>( this, android.R.layout.simple_spinner_item, list);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    AppCompatSpinner spinner = findViewById( spinnerViewId);
    spinner.setAdapter( adapter );

    if ( (curPosition >= 0) && ( curPosition < list.size()) ){
        spinner.setSelection(curPosition);
    }

    spinner.setOnItemSelectedListener( itemSelectedListener );

    return spinner;
}
 
Example 3
Source File: SampleActivity.java    From Material-In with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sample_activity);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    mSpinnerDelay = (AppCompatSpinner) findViewById(R.id.spinner_delay);
    mSpinnerSlide = (AppCompatSpinner) findViewById(R.id.spinner_slide);
    mSpinnerDelay.setAdapter(new ArrayAdapter<>(this, R.layout.spinner, mDelayGravities));
    mSpinnerSlide.setAdapter(new ArrayAdapter<>(this, R.layout.spinner, mSlideGravities));
    mSpinnerDelay.setSelection(1);
    mSpinnerSlide.setSelection(1);
    mSpinnerDelay.setOnItemSelectedListener(this);
    mSpinnerSlide.setOnItemSelectedListener(this);

    mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    mRecyclerView.setAdapter(new Adapter());
    startMaterialIn();
}
 
Example 4
Source File: FeedbackDialog.java    From OmniList with GNU Affero General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    View rootView = LayoutInflater.from(getContext()).inflate(R.layout.dialog_feedback_layout, null);

    feedback = feedback == null ? ModelFactory.getFeedback() : feedback;
    feedback.setFeedbackType(FeedbackType.ABRUPT_CRASH);

    etEmail = rootView.findViewById(R.id.et_email);
    TextInputLayout tilEmail = rootView.findViewById(R.id.til_email);
    etEmail.addTextChangedListener(new EmailFormatWatcher(tilEmail));
    etQuestion = rootView.findViewById(R.id.et_question);
    WatcherTextView wtQuestion = rootView.findViewById(R.id.wt_question);
    wtQuestion.bindEditText(etQuestion);
    AppCompatSpinner spFeedbackTypes = rootView.findViewById(R.id.sp_feedback_types);
    spFeedbackTypes.setOnItemSelectedListener(this);

    return new AlertDialog.Builder(getContext())
            .setTitle(R.string.feedback)
            .setView(rootView)
            .setPositiveButton(R.string.text_send, (dialog, which) -> {
                if (!checkInput()) return;
                if (onSendClickListener != null) onSendClickListener.onSend(FeedbackDialog.this, feedback);
            })
            .setNegativeButton(R.string.text_cancel, null)
            .create();
}
 
Example 5
Source File: SettingsDialogFragment.java    From VideoRecorder with Apache License 2.0 5 votes vote down vote up
private void initSpinner(final AppCompatSpinner sp, List<String> list, String key, final Callback callback) {
    if (list == null) return;
    Camera.Parameters cameraParameters = mCameraController.getCameraParameters();
    final ArrayAdapter<String> adapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_list_item_1, list);
    sp.setAdapter(adapter);
    sp.setSelection(adapter.getPosition(cameraParameters.get(key)), false);
    sp.setOnItemSelectedListener(new SimpleItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            callback.set(adapter.getItem(position));
        }
    });
}
 
Example 6
Source File: SelectorItem.java    From Puff-Android with MIT License 5 votes vote down vote up
@Override
public void setupView(View view) {
    AppCompatSpinner spinner = (AppCompatSpinner)view.findViewById(R.id.settings_spinner);
    spinner.setAdapter(adapter);
    spinner.setOnItemSelectedListener(onItemSelectedListener);
    if (selectedPos != -1)
        spinner.setSelection(selectedPos);
}
 
Example 7
Source File: DownloadManagerToolbar.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes the spinner for the download filter.
 * @param adapter The adapter associated with the spinner.
 */
public void initializeFilterSpinner(FilterAdapter adapter) {
    mSpinner = new AppCompatSpinner(this.getContext());
    mSpinner.setAdapter(adapter);
    mSpinner.setOnItemSelectedListener(adapter);
    addView(mSpinner);
}