android新手请问setOnClickListener这句中那里错了?

Joseph 2011-02-28 06:03:39
android新手请问setOnClickListener这句中那里错了?系统报错说The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the arguments (Activity03.CalculateListener)
以下是代码
package joseph.Activity03;




import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
import android.database.CursorJoiner.Result;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
//1.在Activity03中声明4个控件
//2.要为其中的两个控件设置显示的值
//3.创建一个监听器,监听按钮按下的动作
//4.将监听器类的对象,绑定在按钮对象上
public class Activity03 extends Activity {
/** Called when the activity is first created. */
private EditText factorOne ;
private EditText factorTwo ;
private TextView symbol ;
private Button calculate ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//根据控件的id来取得代表控件的对象
factorOne = (EditText)findViewById(R.id.factorOne);
factorTwo = (EditText)findViewById(R.id.factorTwo);
symbol = (TextView)findViewById(R.id.symbol);
calculate = (Button)findViewById(R.id.calculate);
//为symbol和calculate设置显示的值
symbol.setText(R.string.symbol);
calculate.setText(R.string.calculate);
//将监听器绑定到按钮对象上面
calculate.setOnClickListener(new CalculateListener());


}
class CalculateListener implements OnClickListener{

@Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
//取得两个EditText控件的值
String factorOneStr = factorOne.getText().toString();
String factorTwoStr = factorTwo.getText().toString();
//将这两个值存放到Intent对象中
Intent intent = new Intent();
intent.putExtra("one",factorOneStr);
intent.putExtra("two",factorTwoStr);
intent.setClass(Activity03.this, Result.class);
//使用这个Intent对象来启动ResultActivity
Activity03.this.startActivity(intent);
}

}
}
...全文
5767 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
xhx1203 2013-04-30
  • 打赏
  • 举报
回复
强制类型转化,例如: mainBtn.setOnClickListener((android.view.View.OnClickListener) Listener);
m_o_n_e_y 2012-07-21
  • 打赏
  • 举报
回复
同样的问题啊,求解求指导,各种球啊。谢谢了
love_chen4 2011-09-27
  • 打赏
  • 举报
回复
请问包怎么导呢。直接把前面头文件上加上就可以了么
yweiquan 2011-09-21
  • 打赏
  • 举报
回复
果然是导错了 3QQQ!

[Quote=引用 1 楼 raoyongchao 的回复:]

你导包导错了import android.content.DialogInterface.OnClickListener;这不是View的OnClickListener,请改后再试...
[/Quote]
yxj200624 2011-03-15
  • 打赏
  • 举报
回复
还是不行 [Quote=引用 6 楼 hotkarriver 的回复:]
import android.view.View.OnClickListener;
[/Quote]
hotkarriver 2011-03-03
  • 打赏
  • 举报
回复
import android.view.View.OnClickListener;
Joseph 2011-03-03
  • 打赏
  • 举报
回复
谢谢,我再试试
dinjay 2011-03-01
  • 打赏
  • 举报
回复
eclipse画红线的错误部分,鼠标移动过去eclipse会有提示解决方案
yongyuandeni 2011-03-01
  • 打赏
  • 举报
回复
包错了, 应该是View的OnClickListener
iampy 2011-02-28
  • 打赏
  • 举报
回复
引入的类不对:
import android.content.DialogInterface.OnClickListener;

应该是View类里面的OnClickListener
raoyongchao 2011-02-28
  • 打赏
  • 举报
回复
你导包导错了import android.content.DialogInterface.OnClickListener;这不是View的OnClickListener,请改后再试...

80,350

社区成员

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

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