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?
You don’t have an onCreate() method, so nothing really starts up. onCreate() is the android equivalent of main() in Java. Try using:
Replace with the name of your xml layout file, minus the extension.