如题。一开始我在xml里添加了onclick,并设置可点击 是fragmeng!
但是运行报错。
12-15 01:28:01.380: E/AndroidRuntime(1489): FATAL EXCEPTION: main 12-15 01:28:01.380: E/AndroidRuntime(1489): java.lang.IllegalStateException: Could not find a method redBall(View) in the activity class com.example.activity.LoSSQ for onClick handler on view class android.widget.TextView with id ""ball1"" 12-15 01:28:01.380: E/AndroidRuntime(1489): at android.view.View$1.onClick(View.java:3586) 12-15 01:28:01.380: E/AndroidRuntime(1489): at android.view.View.performClick(View.java:4204) 12-15 01:28:01.380: E/AndroidRuntime(1489): at android.view.View$PerformClick.run(View.java:17355) 12-15 01:28:01.380: E/AndroidRuntime(1489): at android.os.Handler.handleCallback(Handler.java:725) 12-15 01:28:01.380: E/AndroidRuntime(1489): at android.os.Handler.dispatchMessage(Handler.java:92) 12-15 01:28:01.380: E/AndroidRuntime(1489): at android.os.Looper.loop(Looper.java:137) 12-15 01:28:01.380: E/AndroidRuntime(1489): at android.app.ActivityThread.main(ActivityThread.java:5041) 12-15 01:28:01.380: E/AndroidRuntime(1489): at java.lang.reflect.Method.invokeNative(Native Method) 12-15 01:28:01.380: E/AndroidRuntime(1489): at java.lang.reflect.Method.invoke(Method.java:511) 12-15 01:28:01.380: E/AndroidRuntime(1489): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 12-15 01:28:01.380: E/AndroidRuntime(1489): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 12-15 01:28:01.380: E/AndroidRuntime(1489): at dalvik.system.NativeStart.main(Native Method) 12-15 01:28:01.380: E/AndroidRuntime(1489): Caused by: java.lang.NoSuchMethodException: redBall [class android.view.View] 12-15 01:28:01.380: E/AndroidRuntime(1489): at java.lang.Class.getConstructorOrMethod(Class.java:460) 12-15 01:28:01.380: E/AndroidRuntime(1489): at java.lang.Class.getMethod(Class.java:915) 12-15 01:28:01.380: E/AndroidRuntime(1489): at android.view.View$1.onClick(View.java:3579) 12-15 01:28:01.380: E/AndroidRuntime(1489): ... 11 more 12-15 01:33:01.580: I/Process(1489): Sending signal. PID: 1489 SIG: 9 12-15 01:33:02.960: E/Trace(1601): error opening trace file: No such file or directory (2)
要是在fragment.class里设置的话。太麻烦了。请问有什么好的解决方法
方案推荐指数:20
不知道为什么会有这么多textView还不用listView来作,在adapter中直接setOnClickListener就可以了。
方案推荐指数:20
1.fragment和activity通信做个回调就ok了
2.adapter中也可以修改textView,当然 要在ui线程中修改view