Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7654699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:19:24+00:00 2026-05-31T12:19:24+00:00

android 3.0 API Level 11 How do I attach an onTouch Event to the

  • 0

android 3.0 API Level 11

How do I attach an onTouch Event to the button?

TestDebugingActivity.java

package com.example.debuggingTest;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.*;

public class TestDebugingActivity extends Activity {


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


    TextView tv = (TextView)findViewById(R.id.textView1);
    tv.setOnTouchListener((OnTouchListener) this);


    setContentView(R.layout.linear);
  }


}

linear.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >



<TextView
    android:id="@+id/textView1"
    android:layout_width="170dp"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:text="Firstname:"
    android:textAppearance="?android:attr/textAppearanceMedium" />


<EditText
    android:id="@+id/editText1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="10dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginTop="10dp"
    android:inputType="textPersonName" >

    <requestFocus />
</EditText>


<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:text="Lastname:"
    android:textAppearance="?android:attr/textAppearanceMedium" />


<EditText
    android:id="@+id/editText2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:inputType="textPersonName" />


<TextView
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:text="E-mail:"
    android:textAppearance="?android:attr/textAppearanceMedium" />


<EditText
    android:id="@+id/editText3"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:inputType="textEmailAddress" />



<TextView
    android:id="@+id/textView4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginTop="10dp"
    android:text="Gender:"
    android:textAppearance="?android:attr/textAppearanceMedium" />





<RadioGroup
    android:id="@+id/radioGroup1"
    android:layout_width="224dp"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:orientation="horizontal" >


    <RadioButton
        android:id="@+id/radio0"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:checked="true"
        android:text="Male:" />


    <RadioButton
        android:id="@+id/radio1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:text="Female:" />

</RadioGroup>







<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="right"
    android:layout_marginBottom="10dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginTop="10dp"
    android:text="Register" />

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T12:19:26+00:00Added an answer on May 31, 2026 at 12:19 pm

    tv.setOnTouchListener((OnTouchListener) this); is invalid currently because your this is not an OnTouchListener and it does not implement the OnTouchListener interface either.

    There are multiple ways this can be solved. An easy way (not necessarily best) is to have your activity implement OnTouchListener. To do that, you’ll need to declare it and you’ll need to add a single method:

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        // TODO Auto-generated method stub
        return false; // (false: let the event bubble up; true: you handled it)
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Building an app using android.support.v4.app , targeting API level 8. Everything's working as planned
I'm developing an app for Android in Eclipse. Currently I target API level 3,
I'm developing an Android app (API level 8). How do I add some right
I am working on an Android app that utilizes the Google Maps API MapView,
How to decode a base64 encoded string to byte array on Android API level
I'm developing an Android application that is targeting API level 8 (2.2, Froyo). I'm
I noticed that in Android API Level 11 (ICS) MotionEvent has a transform method
I wrote an application using the Android 2.2 SDK (API level 8). It is
There is a new concept in Android: http://android-developers.blogspot.com/2012/01/say-goodbye-to-menu-button.html But it isn't clear fro me.
Is there any Android API that allows me to read the sound level of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.