From 915cf8b2f8eabec7e2ff33df94ea71aeaeabd56d Mon Sep 17 00:00:00 2001 From: sadra amlashi Date: Sat, 27 May 2017 09:05:29 +0430 Subject: [PATCH] Modify if same item choosed --- .idea/misc.xml | 2 +- .../awesomespinner/AwesomeSpinner.java | 4 +-- .../spinnerDefaultSelection.java | 35 +++++++++++++++++++ .../src/main/res/layout/spinner_view.xml | 2 +- 4 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 AwesomeSpinner/src/main/java/com/isapanah/awesomespinner/spinnerDefaultSelection.java diff --git a/.idea/misc.xml b/.idea/misc.xml index 95f0f03..1caa136 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -37,7 +37,7 @@ - + diff --git a/AwesomeSpinner/src/main/java/com/isapanah/awesomespinner/AwesomeSpinner.java b/AwesomeSpinner/src/main/java/com/isapanah/awesomespinner/AwesomeSpinner.java index 23cd4ba..263b426 100644 --- a/AwesomeSpinner/src/main/java/com/isapanah/awesomespinner/AwesomeSpinner.java +++ b/AwesomeSpinner/src/main/java/com/isapanah/awesomespinner/AwesomeSpinner.java @@ -22,7 +22,7 @@ public class AwesomeSpinner extends RelativeLayout { private AppCompatButton _hintButton; - private AppCompatSpinner _spinner; + private spinnerDefaultSelection _spinner; private ImageView _downArrow; private ArrayAdapter _spinnerAdapterString; private ArrayAdapter _spinnerAdapterCharSequence; @@ -51,7 +51,7 @@ public AwesomeSpinner (Context context, AttributeSet attrs, int defStyle) { private void init(AttributeSet attrs) { inflate(getContext(), R.layout.spinner_view, this); this._hintButton = (AppCompatButton) findViewById(R.id.awesomeSpinner_hintButton); - this._spinner = (AppCompatSpinner) findViewById(R.id.awesomeSpinner_spinner); + this._spinner = (spinnerDefaultSelection) findViewById(R.id.awesomeSpinner_spinner); this._downArrow = (ImageView) findViewById(R.id.awesomeSpinner_downArrow); if(attrs != null){ diff --git a/AwesomeSpinner/src/main/java/com/isapanah/awesomespinner/spinnerDefaultSelection.java b/AwesomeSpinner/src/main/java/com/isapanah/awesomespinner/spinnerDefaultSelection.java new file mode 100644 index 0000000..a42aec3 --- /dev/null +++ b/AwesomeSpinner/src/main/java/com/isapanah/awesomespinner/spinnerDefaultSelection.java @@ -0,0 +1,35 @@ +package com.isapanah.awesomespinner; + +import android.content.Context; +import android.support.v7.widget.AppCompatSpinner; +import android.util.AttributeSet; + +/** + * Created by sadra on 5/27/17. + */ + +public class spinnerDefaultSelection extends AppCompatSpinner { + + OnItemSelectedListener listener; + int prevPos = 0; + public spinnerDefaultSelection(Context context) { + super(context); + } + + public spinnerDefaultSelection(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public spinnerDefaultSelection(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + } + + @Override + public void setSelection(int position) { + super.setSelection(position); + if (position == getSelectedItemPosition() && prevPos == position) { + getOnItemSelectedListener().onItemSelected(null, null, position, 0); + } + prevPos = position; + } +} \ No newline at end of file diff --git a/AwesomeSpinner/src/main/res/layout/spinner_view.xml b/AwesomeSpinner/src/main/res/layout/spinner_view.xml index b421250..dd5dc41 100644 --- a/AwesomeSpinner/src/main/res/layout/spinner_view.xml +++ b/AwesomeSpinner/src/main/res/layout/spinner_view.xml @@ -37,7 +37,7 @@ android:layout_height="1dp" /> -