本文主要是介绍不能添加OnClickListener监听事件,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
报错一: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;
而同时添加两种引用又会冲突。
解决办法是,只添加一种引用,代码用到另一种单击事件监听时添加完整路径即可。
例如:
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Toast.makeText(PersonList.this, "Home键被点击", Toast.LENGTH_SHORT).show();
}
});
这篇关于不能添加OnClickListener监听事件的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!