Java
Posted: Sun May 15, 2022 8:10 am
Java
Q3) The following piece of code is designed to show a toast with each Action Up event. But, it shows nothing. Find and explain the problem, then fix it. (7m) 6 7 8 1 view.setOnTouchListener(new View.OnTouchListener() { 2 @Override 3 public boolean on Touch(View v, MotionEvent event) { 4 boolean flag=true; 5 int action = event.getActionMasked(); if(action == MotionEvent.ACTION_DOWN) { // some code goes here flag=!flag; } if(action == MotionEvent. ACTION_UP){ Toast.makeText(self, "Action UP", Toast.LENGTH_SHORT).show(); 12 flag=!flag; 13 } 14 return flag; 15 } 16}); 9 10 11
Q3) The following piece of code is designed to show a toast with each Action Up event. But, it shows nothing. Find and explain the problem, then fix it. (7m) 6 7 8 1 view.setOnTouchListener(new View.OnTouchListener() { 2 @Override 3 public boolean on Touch(View v, MotionEvent event) { 4 boolean flag=true; 5 int action = event.getActionMasked(); if(action == MotionEvent.ACTION_DOWN) { // some code goes here flag=!flag; } if(action == MotionEvent. ACTION_UP){ Toast.makeText(self, "Action UP", Toast.LENGTH_SHORT).show(); 12 flag=!flag; 13 } 14 return flag; 15 } 16}); 9 10 11