Android 使用MSelectListener选择相同的值
这已经被问了很多次了,但我不知道为什么这对我不起作用。我的布局上有多个微调器,它们会根据以前选择的微调器值进行更新。我希望能够在同一微调器上多次选择值 我在使用此代码时遇到问题:Android 使用MSelectListener选择相同的值,android,spinner,Android,Spinner,这已经被问了很多次了,但我不知道为什么这对我不起作用。我的布局上有多个微调器,它们会根据以前选择的微调器值进行更新。我希望能够在同一微调器上多次选择值 我在使用此代码时遇到问题: public class NDSpinner extends Spinner { public NDSpinner(Context context) { super(context); } public NDSpinner(Context context, AttributeSet attrs) {
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());
}
}
}
这应该适用于我现有的代码,但由于某些原因,它不是
我有多个微调器,下面是其中一个,显示我正在使用它:
vTypeSpinner = (NDSpinner) findViewById(R.id.typeSpinner);
以下是我的XML,显示我正在引用它:
<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" />
以下是由于某种原因我以前没有看到的更多日志:
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]]
在微调器中有一个始终位于第一位的虚拟值。并对类似微调器的值进行一次验证检查,检查选择是否正确。如果选择的值是虚拟值,则检查应失败 xml中的
DropDownSpinner
是什么?很抱歉,我更改了它们,LogCat已更新。现在转到12-27 10:05:06.165:E/AndroidRuntime(3089):java.lang.RuntimeException:无法启动活动组件信息{com.example.productguide/com.example.productguide.PowersportsEquivalent}:android.view.InflateException:Binary XML文件行#61:Error inflating class com.example.productguide.NDSpinner
该logcat错误看起来与您的代码无关,但与XML文件中的一个问题有关……以下是我以前由于某种原因没有看到的更多logcat:12-27 10:05:06.165:E/AndroidRuntime(3089):原因:java.lang.ClassNotFoundException:在路径:DexPathList[[zip文件”//data/app/com.example.productguide-2.apk“],NativeLibraryDirectory=[/data/app-lib/com.example.productguide-2,/system/lib]
上未找到类“com.example.productguide.NDSpinner”我不需要具有多个选择的spinner。我需要一个微调器,如果需要,可以再次选择已选择的值。OnItemSelectedListener的工作方式只有在选定值更改时才有效。我需要它,这样我就可以选择任何值,即使它已经被选中。我不想在微调器/数据库中使用任何虚拟值。
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]]