0

First of all, English is not my first language but I will try my best. I'm new to Android. How to discover three or four touch buttons with one finger or one touch as shown in the picture?

enter image description here

I created RelativeLayout containing buttons, @Override onTouch Listener(). I read on Android but I could not understand how it was done. I need a concrete example to understand how touch events are taken from a set of buttons at once.

public class MainActivity extends Activity implements OnTouchListener    {
  Button button1,button2,button3,button4,
  button5,button6,button7,button8,button9;

  RelativeLayout relative;  

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    button1 =(Button)findViewById(R.id.b1);
    button2 =(Button)findViewById(R.id.b2); 
    button3 =(Button)findViewById(R.id.b3); 
    button4 =(Button)findViewById(R.id.b4); 
    button5 =(Button)findViewById(R.id.b5); 
    button6 =(Button)findViewById(R.id.b6); 
    button7 =(Button)findViewById(R.id.b7); 
    button8 =(Button)findViewById(R.id.b8); 
    button9 =(Button)findViewById(R.id.b9); 
    relative = (RelativeLayout)findViewById(R.id.re);

    button1.setOnTouchListener(this);
    button2.setOnTouchListener(this);
    button3.setOnTouchListener(this);
    button4.setOnTouchListener(this);
    button5.setOnTouchListener(this);
    button6.setOnTouchListener(this);
    button7.setOnTouchListener(this);
    button8.setOnTouchListener(this);
    button9.setOnTouchListener(this);
    relative.setOnTouchListener(this);
  }

  @Override
  public boolean onTouch(View v, MotionEvent event) {
    switch(event.getAction()){
      case MotionEvent.ACTION_DOWN:
      break;

      case MotionEvent.ACTION_MOVE:
      //How to find out that touch was done from button13 to button9            
      break;

      case MotionEvent.ACTION_UP:
      break;
    }   
    return true;
  }
}
  • Do you want the user to perform a swipe action connecting the buttons or do you want the user to touch all the buttons at once? The code would probably be different for the two and it would be helpful if you include that information. – iVoid Apr 03 '17 at 10:16
  • I want the user to touch all the buttons at once. In fact, the message toast is not the content of the application . I use it as an example of the application . is the installation of sentences so that when the user touches each time a row of buttons and the touch is a valid sentence. After touching a number of correct sentences to move to the second stage, but what I need now How to touch the buttons together. thank you very much – Borgo Android Apr 03 '17 at 10:43
  • in ACTION_MOVE block you should get X and Y of touch on relative layout, after that calculate what button is under X_Y poxition. Something like that. from buttons you could get width, hight and x, y cordinats of top left corner. – Beyka Apr 03 '17 at 11:07
  • I think it's a complicated way but I try it out . thank you . – Borgo Android Apr 03 '17 at 11:26
  • You might want to take a look at multi touch events tutorial - https://developer.android.com/training/gestures/multi.html – iVoid Apr 03 '17 at 17:02

0 Answers0