Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.Bespoke.AndroidBasics;
- import android.app.Activity;
- import android.content.res.Configuration;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.MotionEvent;
- import android.view.View;
- import android.view.View.OnTouchListener;
- import android.widget.TextView;
- public class SingleTouchTest extends Activity
- implements OnTouchListener {
- StringBuilder builder = new StringBuilder();
- TextView textView;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- textView = new TextView(this);
- textView.setText("Touch and drag (one finger only!)");
- textView.setOnTouchListener(this);
- this.setContentView(textView);
- }
- public boolean onTouch(View v, MotionEvent event) {
- builder.setLength(0); // clear the builder
- switch(event.getAction()) {
- case MotionEvent.ACTION_DOWN:
- builder.append("down, ");
- break;
- case MotionEvent.ACTION_MOVE:
- builder.append("move, ");
- break;
- case MotionEvent.ACTION_CANCEL:
- builder.append("cancel, ");
- break;
- case MotionEvent.ACTION_UP:
- builder.append("up, ");
- break;
- }
- builder.append(event.getX());
- builder.append(", ");
- builder.append(event.getY());
- String text = builder.toString();
- Log.d("TouchTest", text);
- textView.setText(text);
- return true; // Consume the event, if false super.onTouch superceeds us
- }
- @Override
- public void onConfigurationChanged(Configuration newConfig) {
- super.onConfigurationChanged(newConfig);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement