I try to show a toast when user long press android screen....but nothing showing.Why?Simple touch shows toast " touch " work fine! Where is the error?
public class MainActivity extends Activity {
Handler handler = new Handler();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
Runnable mLongPressed = new Runnable() {
public void run() {
Toast.makeText(getBaseContext(),
"Long press",
Toast.LENGTH_LONG).show();
}
};
@Override
public boolean onTouchEvent(MotionEvent event){
if(event.getAction() == MotionEvent.ACTION_DOWN)
Toast.makeText(getBaseContext(),
" touch ",
Toast.LENGTH_LONG).show();
handler.postDelayed(mLongPressed, 1000);
if((event.getAction() == MotionEvent.ACTION_MOVE)||(event.getAction() == MotionEvent.ACTION_UP))
handler.removeCallbacks(mLongPressed);
return super.onTouchEvent(event);
}