Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Connecting Login to Register Activty

Hi I have this code below which I think should connect a register text view to the register activity/layout:

protected void onCreate(Bundle savedInstanceState) {


    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login_activty);

    mRegisterTextView = (TextView)findViewById(R.id.register);
    mRegisterTextView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(LoginActivity.this, RegisterActivity.class);
            startActivity(intent);            }


    });

Here is the layout XML:

<TextView android:layout_marginTop="25dp" android:text="@string/RegisterTitle" android:id="@+id/register" android:layout_below="@id/login" style="@style/LinkBlue"/>

And the Register Class is named Register Activity.

I run the emulator and it does not seem to work...what am I missing?

Thanks so much

Michael

2 Answers

Yongshuo Wang
Yongshuo Wang
5,500 Points

I think you need setOnClickListener to a button, in your code, you add this to your TextView.

Hi So, it needs to be a button?

I have this: < TextView android:layout_marginTop="25dp" android:text="@string/RegisterTitle" android:id="@+id/register" android:layout_below="@id/login" style="@style/LinkBlue"/