Home » Android » android – Implementing events Spinner with Butter Knife

android – Implementing events Spinner with Butter Knife

Posted by: admin May 14, 2020 Leave a comment


First: We need to reference the spinner

Spinner mTypeIdSpinner;

Second: Create string array

<string-array name="type_id_array">

Third: Load the adapter in your activity (onCreate method for example)

private void loadSpinnerIdTypes() {
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
            R.array.type_id_array, android.R.layout.simple_spinner_item);

Fourth: Listen the events

void onItemSelected(int position) {
    Timber.d("Element selected %s ", mTypeIdSpinner.getItemAtPosition(position));
How to&Answers:

You can use @OnItemSelected with method arguments Spinner and int see example:

public void spinnerItemSelected(Spinner spinner, int position) {
    // code here

(works with ButterKnife v. 7.0.1)