The ListView Click Response Code (below) was previously correct:
1 Private class Implements Onitemclicklistener { 2 3 4 @Override 5 Public void int position,long id) { 6 } 7 }
Refer to the previous blog post: http://blog.csdn.net/91program/article/details/39232721
When the new project is used, first prompt Onitemclick to delete the @Override. I directly delete the Onitemclick, and then automatically add the function, found that the automatically added function becomes as follows, the parameters of the parameter has changed, especially the first parameter, from Adapterview to Adapterviewcompat. Code no longer prompts for errors, run it!
1 Private classContactslistitemclicklistenerImplementsOnitemclicklistener {//Adapterviewcompat.onitemclicklistener2 @Override3 Public voidOnitemclick (adapterviewcompat<?> arg0, View arg1,intArg2,4 LongArg3) { 5 //TODO auto-generated Method Stub6 intPosition =arg2; 7 intID = (int) Arg3; 8LOG.I (Phonebookinfo.tag, "position:" + integer.tostring (position) + "ID:" +integer.tostring (id)); 9 } Ten}
There was an error at run time. Tips are as follows:
D/androidruntime (19395): Shutting down VM W/DALVIKVM (19395): Threadid=1:thread exiting with uncaught exception (group=0 X4001B6A8) E/androidruntime (19395): FATAL exception:main e/androidruntime (19395): java.lang.RuntimeException:Unable To start activity componentinfo{com.hs.leozheng.backuprecords/com.hs.leozheng.backuprecords.mainactivity}: Java.lang.classcastexception:com.hs.leozheng.backuprecords.mainactivity$contactslistitemclicklistener E/ Androidruntime (19395): at Android.app.ActivityThread.performLaunchActivity (activitythread.java:1734) e/ Androidruntime (19395): at Android.app.ActivityThread.handleLaunchActivity (activitythread.java:1753) e/ Androidruntime (19395): at android.app.activitythread.access$1500 (activitythread.java:155) E/AndroidRuntime (19395) : At Android.app.activitythread$h.handlemessage (activitythread.java:999) e/androidruntime (19395): at Android.os.Han Dler.dispatchmessage (handler.java:130) e/androidruntime (19395): at Android.os.Looper.loOP (sourcefile:351) E/androidruntime (19395): at Android.app.ActivityThread.main (activitythread.java:3820) e/ Androidruntime (19395): at Java.lang.reflect.Method.invokeNative (Native Method) e/androidruntime (19395): at Java.lang . reflect. Method.invoke (method.java:538) e/androidruntime (19395): at com.android.internal.os.zygoteinit$ Methodandargscaller.run (zygoteinit.java:969) e/androidruntime (19395): at Com.android.internal.os.ZygoteInit.main ( zygoteinit.java:727) E/androidruntime (19395): at Dalvik.system.NativeStart.main (Native Method) e/androidruntime (193 ): Caused by:java.lang.classcastexception:com.hs.leozheng.backuprecords.mainactivity$ Contactslistitemclicklistener E/androidruntime (19395): at Com.hs.leozheng.backuprecords.MainActivity.findViews ( mainactivity.java:140) E/androidruntime (19395): at Com.hs.leozheng.backuprecords.MainActivity.onCreate ( mainactivity.java:57) E/androidruntime (19395): at Android.app.Instrumentation.callActivityOnCreate (instrumentation.java:1082) E/androidruntime (19395): at Android.app.ActivityThread.performLaunchActivity ( activitythread.java:1698) E/androidruntime (19395): ... One more
Comparing the previous code with the current code, the discovery may be caused by adapterviewcompat. Therefore, it is mandatory to declare onitemclicklistener as a member of Adapterview, as follows:
1 Private classContactslistitemclicklistenerImplementsAdapterview.onitemclicklistener {2 @Override3 Public voidOnitemclick (adapterview<?> Parent, view view,intposition,4 LongID) {5 //TODO auto-generated Method Stub6LOG.I (Phonebookinfo.tag, "position:" + integer.tostring (position) + "ID:" +long.tostring (id)); 7 } 8}
This automatically increases the Onitemclick function at last as before.
Run it, right!
Android's ListView Click Response code?