关于点击事件的问题求助。

suce92 2014-08-29 09:07:45
package com.suice.button;

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

public class ButtonActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

Button b=(Button) findViewById(R.id.button);
b.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
// TODO Auto-generated method stub

}
});
}
}



这一行报错:b.setOnClickListener(new OnClickListener() {
内容:
Multiple markers at this line
- The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the arguments (new
OnClickListener(){})
- OnClickListener cannot be resolved to a type

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="点我啊" />

</LinearLayout>

求助。
...全文
84 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
秋杨 2014-08-29
  • 打赏
  • 举报
回复
import android.view.View.OnClickListener;
lionfresh 2014-08-29
  • 打赏
  • 举报
回复
new OnClickListener() 该为new View.OnClickListener()

80,352

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧