在类型视图的方法setOnClickListener(View.OnClickListener)不适用于参数(新DialogInterface.OnClickListener(){}) [英] The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the arguments (new DialogInterface.OnClickListener(){})
问题描述
尝试在onClickListener在我的ListView添加到项目和我得到一个错误,说明:在类型视图的方法setOnClickListener(View.OnClickListener)不适用于参数(新DialogInterface .OnClickListener(){})
就行了:
holder.imageView.setOnClickListener(新OnClickListener(){
这篇文章的作者提及以下内容:
在自定义适配器类,你可以试试里面getView这个code()方法
【JAVA] holder.imageView.setOnClickListener(新OnClickListener(){
@覆盖
公共无效的onClick(视图v){
Toast.makeText(背景下,点击了形象,Toast.LENGTH_LONG).show();
}
}); [/ JAVA]
看起来好像我可能需要修改我当前的实现 - 我只是不知道到底如何。
来源:
公共查看getView(INT位置,查看convertView,父母的ViewGroup){
ViewHolder持有人;
LayoutInflater吹气= context.getLayoutInflater();
如果(convertView == NULL){
convertView = inflater.inflate(R.layout.list_item2,NULL);
持有人=新ViewHolder();
holder.txtSuccess =(TextView中)convertView
.findViewById(R.id.success);
holder.txtCmd =(TextView中)convertView.findViewById(R.id.cmd);
holder.txtPrice =(TextView中)convertView.findViewById(R.id.price);
holder.imageView =(ImageView的)convertView
.findViewById(R.id.thumbnail);
convertView.setTag(保持器);
holder.imageView.setOnClickListener(新OnClickListener(){ 公共无效的onClick(视图v){
Toast.makeText(背景下,点击了形象,
Toast.LENGTH_LONG).show();
}
你可能有错误的导入
。检查您是否进口 DialogInterface.OnClickListener
。仍然可以明确强制参数是这样的:
holder.imageView.setOnClickListener(新View.OnClickListener(){
公共无效的onClick(视图v){
Toast.makeText(背景下,点击了形象,
Toast.LENGTH_LONG).show();
}
Attempting to add an onClickListener to items in my listView and I'm getting an error stating: "The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the arguments (new DialogInterface.OnClickListener(){})"
on the line:
holder.imageView.setOnClickListener(new OnClickListener() {
The author of this article mentioned the following:
In your custom adapter class, you can try this code inside getView() method
[java]holder.imageView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context, "Clicked on image", Toast.LENGTH_LONG).show();
}
});[/java]
It seems as if I might need to modify my current implementation - I'm just not sure exactly how.
Source:
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
LayoutInflater inflater = context.getLayoutInflater();
if (convertView == null) {
convertView = inflater.inflate(R.layout.list_item2, null);
holder = new ViewHolder();
holder.txtSuccess = (TextView) convertView
.findViewById(R.id.success);
holder.txtCmd = (TextView) convertView.findViewById(R.id.cmd);
holder.txtPrice = (TextView) convertView.findViewById(R.id.price);
holder.imageView = (ImageView) convertView
.findViewById(R.id.thumbnail);
convertView.setTag(holder);
holder.imageView.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast.makeText(context, "Clicked on image",
Toast.LENGTH_LONG).show();
}
you probably have the wrong import
. Check if you imported DialogInterface.OnClickListener
. Still you can explicitly force the parameter this way:
holder.imageView.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Toast.makeText(context, "Clicked on image",
Toast.LENGTH_LONG).show();
}
这篇关于在类型视图的方法setOnClickListener(View.OnClickListener)不适用于参数(新DialogInterface.OnClickListener(){})的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!