button.setOnTouchListener(new OnTouchListener()
{
public void onClick(View v)
{
Toast.makeText(MainActivity.this, \"YOUR TEXT\", 5000).show();
}
});
<
Use this code:
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "YOUR TEXT", 5000).show();
}
});
you are putting an ontouchlistener with an onclick listener thats your mistake.
button.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {
Toast.makeText(MainActivity.this, "YOUR TEXT", 5000).show();
return false;
}
});
I also had this problem and I had to do 'fix project setup' which I found after clicking the quick fixes option. I then added a .jar file and it was all good.
and when u use new OnTouchListener() u need to override on onTouch not onClick or change it to
plus.setOnClickListener(new OnClickListener()
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this, "YOUR TEXT", 5000).show();
return false;
}
Check your code: http://developer.android.com/reference/android/view/View.OnTouchListener.html You should use method onTouch.
There are two solutions:
Add import android.view.View.OnTouchListener;
to the beginning of your class
Replace button.setOnTouchListener(new OnTouchListener()
with button.setOnTouchListener(new ViewOnTouchListener()
as Chiral Code suggested.