Create an application that converts the speed from km / h in m / sec and m / sec to km / h
---------------- ---------------- main.xml \u0026lt;? xml version = " 1.0 "encoding =" utf-8 "?>
\u0026lt;TableLayout xmlns: android =" http://schemas.android.com/apk/res/android "android: layout_height = "fill_parent"
android: stretch columns = "1" >
\u0026lt;TableRow>
\u0026lt;
EditText android: id = "@ + id/v1"
android : layout_width = "200px" android
: layout_height = "wrap_content"
/>
\u0026lt;TextView android:text="km/h" />
\u0026lt;/ TableRow>
\u0026lt; ; TableRow>
\u0026lt;EditText
android:id="@+id/v2"
android:layout_width="200px"
android:layout_height="wrap_content"
/>
\u0026lt;TextView android : text = "m / sec" />
\u0026lt;/ TableRow>
\u0026lt;Button
android: id = "@ + id/conv1"
android: layout_width = "200px"
android: layout_height = "wrap_content"
android: onClick = "conv1"
android: text = "converted from km / ham / sec"
/>
\u0026lt;
Button android: id = "+ @ id/conv2"
android: layout_width = "200px" android
: layout_height = "wrap_content"
android: onClick = "conv2"
android: text = "converted from m / sec km / h"
/>
\u0026lt;/ TableLayout>
----------------
convertiVelocita.java----------------
package org.me.convertiVelocita;
import android.app.Activity;
import android.os.Bundle;
import android.content.Context;
import android.widget.*; import android.view.View;
import android.content.Intent;
public class convertiVelocita extends Activity
{
/** Called when the activity is first created. */
final double a=0.2777;
final double b=3.6;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void conv1 (View view){
//da km/h a m/sec
EditText vel1=(EditText)findViewById(R.id.v1);
double kmh=Double.parseDouble(vel1.getText().toString());
double velocita=kmh*a;
String risp=Double.toString(velocita);
EditText vel2=(EditText)findViewById(R.id.v2);
vel2.setText(risp);
vel1.setText("");
}
public void conv2 (View view){
/ / m / sec to km / h
VEL2 EditText = (EditText) findViewById (R.id.v2)
double kmh = Double.parseDouble (vel2.getText (). ToString ());
double speed kmh = * b;
Double.ToString String resp = (speed);
vel1 EditText = (EditText) findViewById (R.id.v1)
vel1.setText (resp);
VEL2. setText ("");
}}
----------------------------- -----------------------------------
Create an application with 3 buttons showing which button was pressed
----------------
qualeBottone.java
----------------package org.me.qualeBottone; import android.app.Activity;
import android.os.Bundle;
import android.content.Context;
import android.widget.*; import android.view.View;
import android.content.Intent;
public class qualeBottone extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView (R.layout.main)
} public void button (View view) {int x =
view.getId ();
TextView view = (TextView) findViewById (R.id.mostra);
if (x == R.id.a1) {
visualizza.setText ("Press the button 1");
} else if (x == R.id.a2) {
visualizza.setText ("Press the button 2");
} else if (x == R.id.a3) {
visualizza.setText ("Press the button 3");}
}}
----------------
main.xml
---------------- \u0026lt;xml version = "1.0" encoding = "utf-8"?>
\u0026lt;LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
android: orientation = "vertical"
android: layout_width = "fill_parent"
android: layout_height = " fill_parent " >
\u0026lt;Button
android: id =" @ + id/a1 "
android: layout_width =" 200px "
android: layout_height = "wrap_content"
android: onClick = "Botton"
android: text = "1"
/>
\u0026lt;Button
android: id = "@ + id/a2 "
android: layout_width =" 200px "android
: layout_height =" wrap_content "
android: onClick =" Botton "
android: text =" 2 "
/>
\u0026lt;Button
android: id = "@ + id/a3"
android: layout_width = "200px" android
: layout_height = "wrap_content"
android: onClick = "Botton"
android: text = " ; 3 "
/>
\u0026lt;TextView android
: layout_width =" fill_parent "
android: layout_height =" wrap_content "
android: id =" @ + id / mostra "
/ >
\u0026lt;/ linear layout>
0 comments:
Post a Comment