安卓,button控件 onclicklistener代码错误 10
代码如下:packagecom.ctt.button.activity;importandroid.os.Bundle;importandroid.app.Activit...
代码如下:
package com.ctt.button.activity;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity {
private Button btn1=null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn1=(Button)findViewById(R.id.btn1);
btn1.setOnClickListener(new onClickListener(){
public void onClick(View v){
Toast.makeText(MainActivity.this, "你点击了按钮", Toast.LENGTH_LONG).show();
}
});
}
}
btn1.setOnClickListener(new onClickListener(){有错误
错误是:
Multiple markers at this line
- Line breakpoint:MainActivity [line: 18] - onCreate(Bundle)
- The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the
arguments (new onClickListener(){})
求大神解答,因为运行不起,就没法进行接下来的学习,急急急!! 展开
package com.ctt.button.activity;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity {
private Button btn1=null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn1=(Button)findViewById(R.id.btn1);
btn1.setOnClickListener(new onClickListener(){
public void onClick(View v){
Toast.makeText(MainActivity.this, "你点击了按钮", Toast.LENGTH_LONG).show();
}
});
}
}
btn1.setOnClickListener(new onClickListener(){有错误
错误是:
Multiple markers at this line
- Line breakpoint:MainActivity [line: 18] - onCreate(Bundle)
- The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the
arguments (new onClickListener(){})
求大神解答,因为运行不起,就没法进行接下来的学习,急急急!! 展开
1个回答
展开全部
btn1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
}
});
new OnClickListener() 的 OnClickListener 大写
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
}
});
new OnClickListener() 的 OnClickListener 大写
追问
你是说全大写吗
追答
O大写就行,按我上面写的一样
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询