0

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]]
LukeG224
  • 155
  • 10
  • What is `DropDownSpinner` in your xml? – a.ch. Dec 27 '13 at 15:59
  • Sorry about that, I changed those, the LogCat is updated. now to `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` – LukeG224 Dec 27 '13 at 16:13
  • that logcat error doesn't look related to your code but to a problem in your xml file... – jkhouw1 Dec 27 '13 at 16:20
  • 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]]` – LukeG224 Dec 27 '13 at 16:28

1 Answers1

0

have one dummy value in the spinner which is always first. And have one validation check for spinner like value selected proper or not. if value selected is a dummy value then check should fail.

Sush
  • 3,864
  • 2
  • 17
  • 35
  • I don't need a spinner that has multiple selections. I need a spinner where I can select the already selected value again, if needed. The way that OnItemSelectedListener works is only when the selected value is changed. I need it so I can select any value even if it is already selected. [This might give more understanding of what I need.](http://stackoverflow.com/questions/7975394/how-to-use-android-spinner-like-a-drop-down-list) – LukeG224 Dec 27 '13 at 16:34
  • I don't want to use any dummy values in my spinners/database. – LukeG224 Dec 27 '13 at 16:47