当我点击可从右到左移动的textview时,我遇到了字幕文本视图的问题。我希望当我点击选框文本时,新活动将显示
当我点击它时,应用程序将崩溃
<TextView
android:text="||EVENT||"
android:id="@+id/MarqueeText"
android:background="#ff010068"
android:textColor="#ffffffff"
android:layout_width="fill_parent"
android:layout_height="22.0sp"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:paddingLeft="15dip"
android:paddingRight="15dip"
android:focusable="true"
android:clickable="true"
android:focusableInTouchMode="false"
android:freezesText="true"
android:onClick="menuevent"
/>
这是来自mainactivity的代码
public void menuevent(View v) {
Intent inn=new Intent();
inn.setClass(this,Fourth.class);
startActivity(inn);
}
这个logcat
10-09 18:42:14.989: E/AndroidRuntime(3513): FATAL EXCEPTION: main
10-09 18:42:14.989: E/AndroidRuntime(3513): java.lang.IllegalStateException: Could not find a method menueventonClick(View) in the activity class com.test.MainActivity for onClick handler on view class android.widget.TextView with id 'MarqueeText'
10-09 18:42:14.989: E/AndroidRuntime(3513): at android.view.View$1.onClick(View.java:3044)
10-09 18:42:14.989: E/AndroidRuntime(3513): at android.view.View.performClick(View.java:3528)
10-09 18:42:14.989: E/AndroidRuntime(3513): at android.view.View$PerformClick.run(View.java:14235)
10-09 18:42:14.989: E/AndroidRuntime(3513): at android.os.Handler.handleCallback(Handler.java:605)
10-09 18:42:14.989: E/AndroidRuntime(3513): at android.os.Handler.dispatchMessage(Handler.java:92)
10-09 18:42:14.989: E/AndroidRuntime(3513): at android.os.Looper.loop(Looper.java:137)
10-09 18:42:14.989: E/AndroidRuntime(3513): at android.app.ActivityThread.main(ActivityThread.java:4424)
10-09 18:42:14.989: E/AndroidRuntime(3513): at java.lang.reflect.Method.invokeNative(Native Method)
10-09 18:42:14.989: E/AndroidRuntime(3513): at java.lang.reflect.Method.invoke(Method.java:511)
10-09 18:42:14.989: E/AndroidRuntime(3513): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:817)
10-09 18:42:14.989: E/AndroidRuntime(3513): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
10-09 18:42:14.989: E/AndroidRuntime(3513): at dalvik.system.NativeStart.main(Native Method)
10-09 18:42:14.989: E/AndroidRuntime(3513): Caused by: java.lang.NoSuchMethodException: menueventonClick [class android.view.View]
10-09 18:42:14.989: E/AndroidRuntime(3513): at java.lang.Class.getConstructorOrMethod(Class.java:460)
10-09 18:42:14.989: E/AndroidRuntime(3513): at java.lang.Class.getMethod(Class.java:915)
10-09 18:42:14.989: E/AndroidRuntime(3513): at android.view.View$1.onClick(View.java:3037)
10-09 18:42:14.989: E/AndroidRuntime(3513): ... 11 more
答案 0 :(得分:0)
使用此
view.getContext().startActivity(
new Intent(view.getContext().getApplicationContext(), Fourth.class)
);