不能添加OnClickListener监听事件

来源:互联网 发布:网店排名优化 编辑:程序博客网 时间:2024/05/22 05:22

报错一:The type new DialogInterface.OnClickListener(){} must implement the inherited abstract method DialogInterface.OnClickListener.onClick(DialogInterface, int)


报错二:The type new View.OnClickListener(){} must implement the inherited abstract method View.OnClickListener.onClick(View)

报错三:The method onClick(DialogInterface, int) of type new View.OnClickListener(){} must override or implement a supertype method


报这个错的根本原因是,在同一个activity中需要用到普通单击监听和弹出框单击监听,而这两种单击事件监听需要引用不同的包。

import android.view.View.OnClickListener;

import android.content.DialogInterface.OnClickListener;

而同时添加两种引用又会冲突。


解决办法是,只添加一种引用,代码用到另一种单击事件监听时添加完整路径即可。

例如:

button.setOnClickListener(new android.view.View.OnClickListener() {
                
                @Override
                public void onClick(View arg0) {
                    // TODO Auto-generated method stub
                    Toast.makeText(PersonList.this, "Home键被点击", Toast.LENGTH_SHORT).show();
                }
          });

0 0
原创粉丝点击