对于TextView类型,未定义SetOnClickListener

时间:2013-11-10 05:22:23

标签: android eclipse

SetOnClickListener出错。它表示方法SetOnClickListener(new View.OnClickListener(){})未定义TextView 类型。为什么呢?

package com.example.testing;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class RegisterActivity extends Activity 
{
@Override
    public void onCreate(Bundle savedInstanceState)
    {

        super.onCreate(savedInstanceState);
        //Set View to register.xml
        setContentView(R.layout.register);

        TextView loginScreen = (TextView) findViewById (R.id.link_to_login);

        //Listening to Login Screen Link
        loginScreen.SetOnClickListener(new View.OnClickListener()
        {

            public void onClick(View arg0)
            {
                //Closing reg screen
                //Switching to Login Screen/closing reg screen
                finish();
            }
        });
    }
}

1 个答案:

答案 0 :(得分:1)

更改为

loginScreen.setOnClickListener(new View.OnClickListener()
{

并导入

import android.view.View.OnClickListener;

并添加@Override Annotation

@Override
public void onClick(View arg0)
{