我收到此错误代码The constructor TextView(new View.OnClickListener(){}) is undefined请帮助我,这是我的代码,它让我难过了几天。
`包com.example.tgtidea;

public class FrontPage extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_front_page);

    Button btn1 = (Button)findViewById(R.id.button1);
    btn1.setOnClickListener(new OnClickListener() {


        public void onClick(View v) {

            EditText comment = (EditText)findViewById(R.id.editText1);
            String comment1 = comment.getText().toString();
            TextView textView = new TextView();
            textView.setTextSize(40);
            textView.setText(comment1);

        }
    });
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.front_page, menu);
    return true;
}

}
`

这不是我的全部代码,而是大部分。做了一些研究,看起来其他人也有类似的问题,只是使用Intent而不是Text View。我是一个年轻的程序员,我只有14岁,请原谅我的无知。谢谢您的帮助。

最佳答案

改变这个

TextView textView = new TextView();


TextView textView = new TextView(FrontPage.this);

但是您的textView未附加到 Activity 。在activity_frot_page中具有LinearLayout或RelativeLayout,对其进行初始化并向其添加textView,而在activity_front_page中具有textView对其进行初始化并将其设置为textView

http://developer.android.com/reference/android/widget/TextView.html

查看上面链接中的公共构造函数

08-06 04:37