I'm trying to change the background of a Button which is in a listview implementing onClickListener but I'm getting this error:
Here is the code:
convertView = inflater.inflate(R.layout.item_quiz3, null);
holder.textView1 = (TextView) convertView
.findViewById(R.id.textView1);
holder.textViewSim = (TextView) convertView
.findViewById(R.id.Sim);
holder.textViewNao = (TextView) convertView
.findViewById(R.id.Nao);
holder.btnSim = (ImageButton) convertView
.findViewById(R.id.btnSim);
holder.btnNao = (ImageButton) convertView
.findViewById(R.id.btnNao);
holder.btnNao.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
v.setBackground(R.drawable.rdb_on);
}
};
}
return convertView; }
}
You have the wrong importation.
Use :
holder.btnNao.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
v.setBackground(R.drawable.rdb_on);
}
};
Or delete the DialogInterface import
Try this one. i think your are missing in close branthesis.')'
holder.btnNao.setOnClickListener(new ListenerT() (or) OnClickListener()
(or) new View.OnClickListener(){
@Override
public void onClick(View v) {
v.setBackground(R.drawable.rdb_on);
}
});
private class ListenerT implements OnClickListener {
public ListenerT() {
}
@Override
public void onClick(View v) {
}
}
The compile time error indicates that you are using Dialog's onclicklistener, but your button is a view not a dialog. Hence you need to explicitly tell the compiler that you need View's OnClickListener
.
holder.btnNao.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.