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 8571243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:44:26+00:00 2026-06-11T18:44:26+00:00

So, I have this code: package com.example.ponto_2d; import android.app.Activity; import android.view.Menu; import android.view.MotionEvent; import

  • 0

So, I have this code:

package com.example.ponto_2d;

import android.app.Activity;
import android.view.Menu;
import android.view.MotionEvent;
import android.widget.TextView;

public class MainActivity extends Activity {
pontos p1=new pontos();
pontos p2=new pontos();

            @Override
            public boolean onTouchEvent(MotionEvent event) {

                TextView tv1 = (TextView) findViewById(R.id.textView2);

                   int eventaction= event.getAction();

                   switch (eventaction){
                   case MotionEvent.ACTION_DOWN:
                       p1.x=event.getX();
                       break;   

                   }

                   tv1.setText(""+p1.x);

                   return true;
            }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

}

This class:

package com.example.ponto_2d;

public class pontos {
        public double x,y;


        public double distancia(pontos p2){

            return Math.sqrt((p2.x-x)*(p2.x-x) + (p2.y-y)*(p2.y-y));
        }
}

This xml layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="38dp"
        android:text="@string/titulo_app"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="30dp"
        android:layout_toRightOf="@+id/textView1"
        android:text="@string/valor"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView2"
        android:layout_alignBottom="@+id/textView2"
        android:layout_alignRight="@+id/textView1"
        android:text="@string/distancia_1"
        android:textAppearance="?android:attr/textAppearanceMedium" />


</RelativeLayout>

I think that it is all right, but when I run the emulator, I get nothing, not even a single button.
Any idea about what what could be the problem?

  • 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-06-11T18:44:27+00:00Added an answer on June 11, 2026 at 6:44 pm

    You don’t have an onCreate() method, so nothing really starts up. onCreate() is the android equivalent of main() in Java. Try using:

    public class MainActivity extends Activity {
    pontos p1=new pontos();
    pontos p2=new pontos();
    
    
        @Override
        public void onCreate(Bundle bundle) {
            super.onCreate(bundle);
            setContentView(R.layout.<yourXMLFile>);
        }
                @Override
                public boolean onTouchEvent(MotionEvent event) {
    
                    TextView tv1 = (TextView) findViewById(R.id.textView2);
    
                       int eventaction= event.getAction();
    
                       switch (eventaction){
                       case MotionEvent.ACTION_DOWN:
                           p1.x=event.getX();
                           break;   
    
                       }
    
                       tv1.setText(""+p1.x);
    
                       return true;
                }
    
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.activity_main, menu);
            return true;
        }
    
    }
    

    Replace with the name of your xml layout file, minus the extension.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: package com.powergroupbd.timer; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.CountDownTimer;
This is my code: package com.example.testcode; import android.app.ListFragment; import android.app.LoaderManager; import android.content.CursorLoader; import android.content.Loader;
I have this code: package com.example.pr; import android.media.MediaPlayer; public class Audio{ MediaPlayer mp; public
Here is my main: package com.example.frags; import android.app.Activity; import android.os.Bundle; import android.support.v4.app.FragmentTransaction; import android.support.v4.app.Fragment;
I have found this piece of code in the Haskell sendfile package: http://patch-tag.com/r/mae/sendfile/snapshot/current/content/pretty/src/Network/Socket/SendFile/Linux.hsc --
We have some code kicking around that uses this old internal Sun package for
My directory structure is: ABC/src/com/example/model/a.java ABC/src/com/example/web/b.java Code for a.java : package com.example.model; public class
I have a scala object defined like the following: package com.example object Foo {
I'm going by the following code example to dynamically build a preference activity. http://www.linuxtopia.org/online_books/android/devguide/guide/samples/ApiDemos/src/com/example/android/apis/app/PreferencesFromCode.html
I Have just started learning Android, this is the code of my java file.

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.