I have imagebutton and I want to write setOnClickListener method with toggle click (like toggleButton). I know how working togglebutton but I do not need to use it. it is a possible to write toggleclick method in imagebutton. I wrote some code but not working such as togglebutton
strada_chart.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if(arg0.isClickable()==true)
{
Toast.makeText(getApplicationContext(), "1", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(getApplicationContext(), "2", Toast.LENGTH_SHORT).show();
}
}
});
Try this..
likeBtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if(fun) {
likeBtn.setImageResource(R.drawable.unlike);
fun=false;
} else {
fun=true;
likeBtn.setImageResource(R.drawable.like);
Toast.makeText(
getApplicationContext(),
"Changed",
Toast.LENGTH_LONG
).show();
}
}
});