Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- final TextView textView = (TextView)findViewById(R.id.textView);
- // this is the view on which you will listen for touch events
- final View touchView = findViewById(R.id.ll);
- touchView.setOnTouchListener(new View.OnTouchListener() {
- @Override
- public boolean onTouch(View v, MotionEvent event) {
- textView.setText("Touch coordinates : " + String.valueOf(event.getX()) + "x" + String.valueOf(event.getY()));
- return true;
- }
- });
- }
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:id="@+id/ll"
- android:orientation="vertical">
- <Button
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="New Button"
- android:id="@+id/button"
- android:layout_weight="0.50" />
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="New Text"
- android:id="@+id/textView2"
- android:layout_weight="0.50" />
- <TextView
- android:id="@+id/textView"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="Hello World, TestActivity" />
- </LinearLayout>
Add Comment
Please, Sign In to add comment