Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use this function : <a href="http://developer.android.com/reference/android/view/View.html#setOnTouchListener(android.view.View.OnTouchListener)" rel="noreferrer">http://developer.android.com/reference/android/view/View.html#setOnTouchListener(android.view.View.OnTouchListener)</a></p> <p>You will probably put it in your onCreate method roughly this way (tested this time) :</p> <p>Activity onCreate code</p> <pre><code>@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.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.touchView); 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; } }); } </code></pre> <p>layout code</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;TextView android:id="@+id/touchView" android:background="#f00" android:layout_weight="1" android:layout_width="fill_parent" android:layout_height="wrap_content" /&gt; &lt;TextView android:id="@+id/textView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Hello World, TestActivity" /&gt; &lt;/LinearLayout&gt; </code></pre> <p><strong>Edit</strong>: I tried my code and indeed there were a few errors. Anyway, with the layout I give you here it works on my emulator. Can you provide maybe more code/context so I can see what's wrong?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload