New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make Spinner widget open from start-of-list when nothing is selected #1955
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.odk.collect.android.views; | ||
|
||
import android.content.Context; | ||
import android.support.v7.widget.AppCompatSpinner; | ||
import android.util.AttributeSet; | ||
|
||
/** | ||
* Created by vaibhav on 1/3/18. | ||
*/ | ||
|
||
public class CustomSpinner extends AppCompatSpinner { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What would a more descriptive name be? How about |
||
|
||
private boolean toggleFlag = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should also have a more descriptive name. I would call it |
||
|
||
public CustomSpinner(Context context, AttributeSet attrs, | ||
int defStyle, int mode) { | ||
super(context, attrs, defStyle, mode); | ||
} | ||
|
||
public CustomSpinner(Context context, AttributeSet attrs, | ||
int defStyle) { | ||
super(context, attrs, defStyle); | ||
} | ||
|
||
public CustomSpinner(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
} | ||
|
||
public CustomSpinner(Context context, int mode) { | ||
super(context, mode); | ||
} | ||
|
||
public CustomSpinner(Context context) { | ||
super(context); | ||
} | ||
|
||
@Override | ||
public int getSelectedItemPosition() { | ||
// this toggle is required because this method will get called in other | ||
// places too, the most important being called for the | ||
// OnItemSelectedListener | ||
if (!toggleFlag && super.getSelectedItemPosition() == getAdapter().getCount() - 1) { | ||
return 0; // get us to the first element | ||
} | ||
return super.getSelectedItemPosition(); | ||
} | ||
|
||
@Override | ||
public boolean performClick() { | ||
// this method shows the list of elements from which to select one. | ||
// we have to make the getSelectedItemPosition to return 0 so you can | ||
// fool the Spinner and let it think that the selected item is the first | ||
// element | ||
toggleFlag = false; | ||
boolean result = super.performClick(); | ||
toggleFlag = true; | ||
return result; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please replace this comment with a description of the class. The very top should have a copyright notice with your name (you are the copyright holder) -- https://github.com/opendatakit/collect/blob/master/LICENSE.md#appendix-how-to-apply-the-apache-license-to-your-work