title: Motion Event Capturing in android
body: <p>i have written code for an application.</p>
  
  <p>The application layout is like this.</p>
  
  <p>0 1 2 3 4 </p>
  
  <p>5 6 7 8 9 </p>
  
  <p>now when the user touches one key(The user hold his finger on a button say 5),that its text  should be entered in text box as "5 down". But when the user releases the key then the text should be  set to "5 up". but before the key release done, if the user slides on the layout with his finger to 6 , then it should be detected and the text should be set to "down 6". it should proceed like that ,but when the user releases the key then the text should be set to  "up <strong>the key currently touched</strong>". i have used the MOTION_UP,MOTION_DOWN , MOTION_MOVE things but i am not getting how to accomplish it exactly. please throw some light for me on this issue. what is happening is when i slide from 5 to 6, the event is still in "down 5" but when i take off my finger then it is setting to "up 5". but i want the sliding approach to be done. so please give me some idea of how to do this.</p>
  
  <p>here is my code</p>
  
  <pre><code>@Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      // select_btn = (Button) findViewById(R.id.ok);
      // home_btn = (Button) findViewById(R.id.home);
      et = (EditText) findViewById(R.id.entry);
      et.setText("", TextView.BufferType.EDITABLE);
      b = new Bundle();
  
  
      try {
          Thread.sleep(2000);
      } catch (InterruptedException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
      for (int i = 0; i &lt; mybtn.length; i++) {
          String btnid = "btn" + i;
          int resid = getResources().getIdentifier(btnid, "id",
                  getPackageName());
          mybtn[i] = (Button) findViewById(resid);
          mybtn[i].setOnTouchListener(this);
  
      }
  
  
  
  }
  
  
  @Override
  public boolean onTouch(View v, MotionEvent event) {
      // TODO Auto-generated method stub
      String s = null;
      s = ((Button) v).getText().toString().trim();
      switch (event.getAction()) {
      // case MotionEvent.ACTION_MOVE:
      // Do some stuff
      // et.setText("move android"+s, TextView.BufferType.EDITABLE );
      // break;
  
      case MotionEvent.ACTION_DOWN:
          et.setText("down android" + s, TextView.BufferType.EDITABLE);
          // Do some stuff
          break;
      case MotionEvent.ACTION_UP:
          et.setText("up android" + s, TextView.BufferType.EDITABLE);
  
      }
      return true;
  }
  </code></pre>