You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用TextView跳转至其他Activity?添加setOnClickListener后APP无响应求助

Fixing TextView Click to Navigate to Another Activity (and Resolving Unresponsive Clicks)

Hey there! Let's break down why your TextView click isn't triggering the Activity navigation, and fix it step by step.

First, Common Causes for Unresponsive TextView Clicks

TextViews aren't clickable by default—this is the most likely culprit. Let's cover all the key checks and fixes:

1. Make Your TextView Clickable

Add the android:clickable="true" attribute to your TextView in the layout XML. You can also add visual cues to let users know it's interactive:

<TextView
    android:id="@+id/register"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Go to Registration"
    android:clickable="true"
    android:textColor="@android:color/holo_blue_light"
    android:textStyle="underline" />

If you prefer setting it in code instead, add this line after finding the TextView:

e3.setClickable(true);

2. Verify Target Activity is Registered in AndroidManifest.xml

If your registration Activity isn't listed in the manifest, the app will fail to launch it (and might appear unresponsive or crash). Add this inside the <application> tag:

<activity android:name=".registration" />

Note: Java class naming conventions require class names to start with a capital letter. It's better to rename your activity class to Registration (instead of registration) to avoid confusion, then update the manifest and Intent to use Registration.class.

3. Fix the Intent and Click Listener Code

Assuming you've fixed the class name to Registration, here's the corrected click listener code (with minor cleanup):

TextView e3 = (TextView) findViewById(R.id.register);
e3.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent move = new Intent(MainActivity.this, Registration.class);
        startActivity(move);
    }
});
  • Double-check that MainActivity.this is valid: if this code is inside a Fragment, replace it with getActivity() instead.
  • Ensure there are no typos in the Activity class name (case-sensitive!).

If It's Still Not Working...

Check Android Studio's Logcat for error messages. Look for exceptions like ClassNotFoundException (means the Activity isn't registered or the class name is wrong) or NullPointerException (means e3 wasn't found—check your layout's android:id matches R.id.register).

内容的提问来源于stack exchange,提问作者Priya Lorha

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 06:59:33