Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="utf-8"?>
- <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context=".MainActivity">
- <EditText
- android:id="@+id/editText01"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textSize="15pt"
- android:ems="5"
- android:inputType="number"
- app:layout_constraintLeft_toLeftOf="parent"
- app:layout_constraintTop_toTopOf="parent"
- />
- <TextView
- android:id="@+id/textView01"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="km/h"
- android:textSize="15pt"
- app:layout_constraintLeft_toRightOf="@id/editText01"
- app:layout_constraintTop_toTopOf="parent"
- android:layout_margin="5pt"
- />
- <Button
- android:id="@+id/button01"
- android:layout_width="0pt"
- android:layout_height="wrap_content"
- android:text="Oblicz"
- android:textSize="10pt"
- android:layout_margin="5pt"
- app:layout_constraintTop_toBottomOf="@id/editText01"
- app:layout_constraintLeft_toLeftOf="parent"
- app:layout_constraintRight_toRightOf="parent"
- android:onClick="calculate"
- />
- <TextView
- android:id="@+id/textView02"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text=".............."
- android:textSize="15pt"
- app:layout_constraintLeft_toLeftOf="parent"
- app:layout_constraintTop_toBottomOf="@id/button01"
- android:layout_margin="5pt"
- />
- <TextView
- android:id="@+id/textView03"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="m/s"
- android:textSize="15pt"
- app:layout_constraintLeft_toRightOf="@id/textView02"
- app:layout_constraintTop_toBottomOf="@id/button01"
- android:layout_margin="5pt"
- />
- </androidx.constraintlayout.widget.ConstraintLayout>
- ****************************************************************
- package com.example.k03;
- import androidx.appcompat.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.EditText;
- import android.widget.TextView;
- public class MainActivity extends AppCompatActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- }
- public void calculate(View view) {
- double xx = 0;
- EditText liczba = findViewById(R.id.editText01);
- TextView wynik = findViewById(R.id.textView02);
- String x;
- x = liczba.getText().toString();
- xx = Double.parseDouble(x);
- xx=xx*1000/3600;
- wynik.setText(String.valueOf(xx));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement