按钮setonclicklistener错误 [英] Button setonclicklistener error

查看:90
本文介绍了按钮setonclicklistener错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



当我把这个下面的行:

p>

  button.setOnClickListener(this); 

然后运行应用程序,然后它不运行,并显示一条消息应用程序强制关闭 / p>

请问如何在Android 2.2中设置按钮onclick事件?

解决方案

看看下面的代码是否适合你...

  button.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v)
{
Toast.makeText(getApplicationContext(),Hello World,Toast.LENGTH_LONG).show();
}
});

请记住添加}); 结束。


I am having a problem right now with setOnClickListener.

When i put this following line:

button.setOnClickListener(this);

And run the application then it does not run and shows a message that "Application closed forcefully".

Could you please help me how I can set button onclick event in Android 2.2?

解决方案

See if the code below works for you...

button.setOnClickListener(new OnClickListener() {              
  @Override
  public void onClick(View v) 
  {
      Toast.makeText(getApplicationContext(), "Hello World", Toast.LENGTH_LONG).show();
  }    
});      

Remember to add }); at the end.

这篇关于按钮setonclicklistener错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆