Skip to content

Commit

Permalink
Modify if same item choosed
Browse files Browse the repository at this point in the history
  • Loading branch information
sadra committed May 27, 2017
1 parent eecf699 commit 915cf8b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public class AwesomeSpinner extends RelativeLayout {

private AppCompatButton _hintButton;
private AppCompatSpinner _spinner;
private spinnerDefaultSelection _spinner;
private ImageView _downArrow;
private ArrayAdapter<String> _spinnerAdapterString;
private ArrayAdapter<CharSequence> _spinnerAdapterCharSequence;
Expand Down Expand Up @@ -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){
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
2 changes: 1 addition & 1 deletion AwesomeSpinner/src/main/res/layout/spinner_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
android:layout_height="1dp" />


<android.support.v7.widget.AppCompatSpinner
<com.isapanah.awesomespinner.spinnerDefaultSelection
android:id="@+id/awesomeSpinner_spinner"
android:layout_alignBottom="@+id/awesomeSpinner_hintButton"
android:layout_width="match_parent"
Expand Down

0 comments on commit 915cf8b

Please sign in to comment.