setOnTouchListener() is giving me an error

前端 未结 7 523
北恋
北恋 2021-01-27 18:25
button.setOnTouchListener(new OnTouchListener()
{
  public void onClick(View v)
  {
      Toast.makeText(MainActivity.this, \"YOUR TEXT\", 5000).show();
  }
});
<         


        
7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-27 19:11

    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;
            }
    

提交回复
热议问题