From 8e5821bcdc54b6e87b238fc6802d7d8496bf6f45 Mon Sep 17 00:00:00 2001 From: John Carlson Date: Sun, 8 Jan 2017 10:24:39 -0600 Subject: [PATCH] Add support for Spinner --- .../untriggered/sample/MainActivity.java | 18 +++++++- app/src/main/res/layout/activity_main.xml | 6 +++ app/src/main/res/values/strings.xml | 5 +++ .../untriggered/UntriggeredSpinner.java | 45 +++++++++++++++++++ 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 untriggered/src/main/java/com/commit451/untriggered/UntriggeredSpinner.java diff --git a/app/src/main/java/com/commit451/untriggered/sample/MainActivity.java b/app/src/main/java/com/commit451/untriggered/sample/MainActivity.java index 02f2255..a7e10d8 100644 --- a/app/src/main/java/com/commit451/untriggered/sample/MainActivity.java +++ b/app/src/main/java/com/commit451/untriggered/sample/MainActivity.java @@ -5,6 +5,7 @@ import android.os.Bundle; import android.view.View; import android.view.ViewGroup; +import android.widget.AdapterView; import android.widget.CompoundButton; import android.widget.RatingBar; import android.widget.SeekBar; @@ -13,6 +14,7 @@ import com.commit451.untriggered.UntriggeredRadioButton; import com.commit451.untriggered.UntriggeredRatingBar; import com.commit451.untriggered.UntriggeredSeekBar; +import com.commit451.untriggered.UntriggeredSpinner; import com.commit451.untriggered.UntriggeredSwitchCompat; public class MainActivity extends AppCompatActivity { @@ -27,7 +29,8 @@ protected void onCreate(Bundle savedInstanceState) { final UntriggeredRadioButton radioButton = (UntriggeredRadioButton) findViewById(R.id.radio); final UntriggeredSwitchCompat switchCompat = (UntriggeredSwitchCompat) findViewById(R.id.switch_thing); final UntriggeredRatingBar ratingBar = (UntriggeredRatingBar) findViewById(R.id.ratingbar); - final UntriggeredSeekBar seekBar= (UntriggeredSeekBar) findViewById(R.id.seekbar); + final UntriggeredSeekBar seekBar = (UntriggeredSeekBar) findViewById(R.id.seekbar); + final UntriggeredSpinner spinner = (UntriggeredSpinner) findViewById(R.id.spinner); checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override @@ -74,6 +77,18 @@ public void onStopTrackingTouch(SeekBar seekBar) { } }); + spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + Snackbar.make(root, "Spinner set to " + position + " and I am triggered!", Snackbar.LENGTH_SHORT) + .show(); + } + + @Override + public void onNothingSelected(AdapterView parent) { + + } + }); findViewById(R.id.button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -82,6 +97,7 @@ public void onClick(View v) { switchCompat.setCheckedUntriggered(!switchCompat.isChecked()); seekBar.setProgressUntriggered(50); ratingBar.setRatingUntriggered(2.5f); + spinner.setSelectionUntriggered(1, true); } }); } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 15ddbe1..644505e 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -39,6 +39,12 @@ android:layout_width="match_parent" android:layout_height="wrap_content" /> + +