This has been asked many times here but I have no idea why this is not working for me. I have multiple spinners on my layout and they are updated depending on the selected previous spinner(s) values. I want to be able to select a value more than once on the same spinner.
I am having a problem using this code:
public class NDSpinner extends Spinner {
public NDSpinner(Context context)
{ super(context); }
public NDSpinner(Context context, AttributeSet attrs)
{ super(context, attrs); }
public NDSpinner(Context context, AttributeSet attrs, int defStyle)
{ super(context, attrs, defStyle); }
@Override public void
setSelection(int position, boolean animate)
{
boolean sameSelected = position == getSelectedItemPosition();
super.setSelection(position, animate);
if (sameSelected) {
// Spinner does not call the OnItemSelectedListener if the same item is selected, so do it manually now
getOnItemSelectedListener().onItemSelected(this, getSelectedView(), position, getSelectedItemId());
}
}
@Override public void
setSelection(int position)
{
boolean sameSelected = position == getSelectedItemPosition();
super.setSelection(position);
if (sameSelected) {
// Spinner does not call the OnItemSelectedListener if the same item is selected, so do it manually now
getOnItemSelectedListener().onItemSelected(this, getSelectedView(), position, getSelectedItemId());
}
}
}
This should be working with my existing code, but for some reason it is not.
I have multiple spinners and here is just one of them showing that I am using it:
vTypeSpinner = (NDSpinner) findViewById(R.id.typeSpinner);
Here is my XML showing that I am referencing it:
<com.example.productguide.NDSpinner
android:id="@+id/typeSpinner"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignLeft="@+id/textView01"
android:layout_centerVertical="true"
android:layout_below="@+id/textView01" />
Here is the LogCat error
12-27 10:05:06.165: E/AndroidRuntime(3089): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.productguide/com.example.productguide.PowersportsEquivalent}: android.view.InflateException: Binary XML file line #61: Error inflating class com.example.productguide.NDSpinner
Here is more of the LogCat that I didn't see before for some reason:
12-27 10:05:06.165: E/AndroidRuntime(3089): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.productguide.NDSpinner" on path: DexPathList[[zip file "/data/app/com.example.productguide-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.productguide-2, /system/lib]]