本文介绍了我有一个错误:setOnItemClickListener不能与微调器一起使用,有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请注意,这是我下面的代码,我在下面粘贴错误消息:
我试图在微调器上使用 setOnItemClickListener
,这是允许的吗?
Kindly This is my code below, and I am pasting the error messages underneath: I am trying to use setOnItemClickListener
on the spinner, is it permissible?
@Override
public void onItemClick(AdapterView<?> arg0, View v, int index, long arg3) {
if (quantity[index]=="Meter" ){
s1="Meter";
Toast.makeText(v.getContext(), "convert from meter",Toast.LENGTH_SHORT).show();
}
}
});
convertto.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> arg, View v1, int index1, long arg4)
{
if ((quantity[index1]=="Meter") && (s1.equalsIgnoreCase("Meter")))
{
Toast.makeText(v1.getContext(), " to meter",Toast.LENGTH_SHORT).show();
var2=var1;
lresult.setText("" + var2);
}
}
});
}
}
这里是错误
FATAL EXCEPTION: main
07-04 09:48:39.912: E/AndroidRuntime(694): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.a2zunitconverter.miniproject/com.a2zunitconverter.miniproject.lenght}: java.lang.RuntimeException: setOnItemClickListener cannot be used with a spinner.
07-04 09:48:39.912: E/AndroidRuntime(694): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
07-04 09:48:39.912: E/AndroidRuntime(694): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
07-04 09:48:39.912: E/AndroidRuntime(694): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
07-04 09:48:39.912: E/AndroidRuntime(694): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
07-04 09:48:39.912: E/AndroidRuntime(694): at android.os.Handler.dispatchMessage(Handler.java:99)
07-04 09:48:39.912: E/AndroidRuntime(694): at android.os.Looper.loop(Looper.java:123)
07-04 09:48:39.912: E/AndroidRuntime(694): at android.app.ActivityThread.main(ActivityThread.java:3683)
07-04 09:48:39.912: E/AndroidRuntime(694): at java.lang.reflect.Method.invokeNative(Native Method)
07-04 09:48:39.912: E/AndroidRuntime(694): at java.lang.reflect.Method.invoke(Method.java:507)
07-04 09:48:39.912: E/AndroidRuntime(694): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-04 09:48:39.912: E/AndroidRuntime(694): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-04 09:48:39.912: E/AndroidRuntime(694): at dalvik.system.NativeStart.main(Native Method)
07-04 09:48:39.912: E/AndroidRuntime(694): Caused by: java.lang.RuntimeException: setOnItemClickListener cannot be used with a spinner.
07-04 09:48:39.912: E/AndroidRuntime(694): at android.widget.Spinner.setOnItemClickListener(Spinner.java:102)
07-04 09:48:39.912: E/AndroidRuntime(694): at com.a2zunitconverter.miniproject.lenght.onCreate(lenght.java:31)
07-04 09:48:39.912: E/AndroidRuntime(694): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-04 09:48:39.912: E/AndroidRuntime(694): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
07-04 09:48:39.912: E/AndroidRuntime(694): ... 11 more
推荐答案
查看logcat的第一行:
See the first line of your logcat:
java.lang.RuntimeException: setOnItemClickListener cannot be used with a spinner.
setOnItemClickListener
不能与<$一起使用C $ C>微调。改为使用 setOnItemSelectedListener
。
这篇关于我有一个错误:setOnItemClickListener不能与微调器一起使用,有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!