Guest User

Untitled

a guest
Jun 30th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. @Override
  2. public void onCreate(Bundle savedInstanceState)
  3. {
  4. super.onCreate(savedInstanceState);
  5. setContentView(R.layout.activity_main);
  6. final TextView textView = (TextView)findViewById(R.id.textView);
  7. // this is the view on which you will listen for touch events
  8. final View touchView = findViewById(R.id.ll);
  9. touchView.setOnTouchListener(new View.OnTouchListener() {
  10. @Override
  11. public boolean onTouch(View v, MotionEvent event) {
  12. textView.setText("Touch coordinates : " + String.valueOf(event.getX()) + "x" + String.valueOf(event.getY()));
  13. return true;
  14. }
  15. });
  16. }
  17.  
  18. <?xml version="1.0" encoding="utf-8"?>
  19. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  20. android:layout_width="fill_parent"
  21. android:layout_height="fill_parent"
  22. android:id="@+id/ll"
  23. android:orientation="vertical">
  24.  
  25. <Button
  26. android:layout_width="match_parent"
  27. android:layout_height="wrap_content"
  28. android:text="New Button"
  29. android:id="@+id/button"
  30. android:layout_weight="0.50" />
  31.  
  32. <TextView
  33. android:layout_width="match_parent"
  34. android:layout_height="wrap_content"
  35. android:text="New Text"
  36. android:id="@+id/textView2"
  37. android:layout_weight="0.50" />
  38.  
  39. <TextView
  40. android:id="@+id/textView"
  41. android:layout_width="fill_parent"
  42. android:layout_height="wrap_content"
  43. android:text="Hello World, TestActivity" />
  44. </LinearLayout>
Add Comment
Please, Sign In to add comment