Я не хочу отображать сообщение с помощью класса Toast ⇐ JAVA
Я не хочу отображать сообщение с помощью класса Toast
I made an application to find the key using coordinates. Everything seems to be working, but the notification of the location does not come. I made the notification using the Toast class. Here is the code:
MainActivity:
private TextView coordinatesOut; private float x; private float y; private String sDown; private String sMove; private String sUp; private final float xKey = 568; private final float yKey = 150; private final float deltaKey = 50; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); coordinatesOut = findViewById(R.id.coordinatesOut); coordinatesOut.setOnTouchListener(listener); } private View.OnTouchListener listener = new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { x = motionEvent.getX(); y = motionEvent.getY(); switch (motionEvent.getAction()) { case MotionEvent.ACTION_DOWN: sDown = "Нажатие: координата X = " + x + ", координата y = " + y; sMove = ""; sUp = ""; break; case MotionEvent.ACTION_MOVE: sMove = "Движение: координата X = " + x + ", координата y = " + y; if (x < (xKey + deltaKey) && x > (xKey - deltaKey) && y < (yKey + deltaKey) && y > (yKey - deltaKey)) { Toast toast = Toast.makeText(getApplicationContext(), R.string.successful_search_One, Toast.LENGTH_SHORT); toast.show(); } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: sMove = ""; sUp = "Отпускание: координата X = " + x + ", координата y = " + y; break; } coordinatesOut.setText(sDown + "\n" + sMove + "\n" + sUp); return true; } }; } I don't know what to say here. I tried to figure it out somehow, but I never figured it out.
Источник: https://stackoverflow.com/questions/780 ... oast-class
I made an application to find the key using coordinates. Everything seems to be working, but the notification of the location does not come. I made the notification using the Toast class. Here is the code:
MainActivity:
private TextView coordinatesOut; private float x; private float y; private String sDown; private String sMove; private String sUp; private final float xKey = 568; private final float yKey = 150; private final float deltaKey = 50; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); coordinatesOut = findViewById(R.id.coordinatesOut); coordinatesOut.setOnTouchListener(listener); } private View.OnTouchListener listener = new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { x = motionEvent.getX(); y = motionEvent.getY(); switch (motionEvent.getAction()) { case MotionEvent.ACTION_DOWN: sDown = "Нажатие: координата X = " + x + ", координата y = " + y; sMove = ""; sUp = ""; break; case MotionEvent.ACTION_MOVE: sMove = "Движение: координата X = " + x + ", координата y = " + y; if (x < (xKey + deltaKey) && x > (xKey - deltaKey) && y < (yKey + deltaKey) && y > (yKey - deltaKey)) { Toast toast = Toast.makeText(getApplicationContext(), R.string.successful_search_One, Toast.LENGTH_SHORT); toast.show(); } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: sMove = ""; sUp = "Отпускание: координата X = " + x + ", координата y = " + y; break; } coordinatesOut.setText(sDown + "\n" + sMove + "\n" + sUp); return true; } }; } I don't know what to say here. I tried to figure it out somehow, but I never figured it out.
Источник: https://stackoverflow.com/questions/780 ... oast-class
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение