Created
August 22, 2018 23:28
-
-
Save thbighead/7a6f6adc0e86f6a9c2c10b43889f3409 to your computer and use it in GitHub Desktop.
Tela de app Android que converte Celsius para Fahrenheit.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.labc.tconversor; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.TextView; | |
import android.widget.Toast; | |
public class MainActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
} | |
public void convert(View view) { | |
TextView edtCelsius = (TextView)findViewById(R.id.edtCelsius); | |
TextView edtFahrenheit = (TextView)findViewById(R.id.edtFahrenheit); | |
double celsius = Double.valueOf(edtCelsius.getText().toString()); | |
double fahrenheit = (celsius/5)*9+32; | |
//CRIACAO DA MENSAGEM QUE APARECE POR 5S | |
Toast toast = Toast.makeText(this, "A temperatura em Fahrenheit " + fahrenheit, Toast.LENGTH_LONG); | |
toast.show(); | |
edtFahrenheit.setText(String.valueOf(fahrenheit)); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<RelativeLayout 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/edtCelsius" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_alignParentTop="true" | |
android:layout_centerHorizontal="true" | |
android:layout_marginTop="101dp" | |
android:ems="10" | |
android:inputType="textPersonName" /> | |
<TextView | |
android:id="@+id/title" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_alignParentTop="true" | |
android:layout_centerHorizontal="true" | |
android:layout_marginTop="72dp" | |
android:text="Informe a temperatura em Celsius" /> | |
<Button | |
android:id="@+id/submit" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_alignParentTop="true" | |
android:layout_centerHorizontal="true" | |
android:layout_marginTop="173dp" | |
android:onClick="convert" | |
android:text="Converter" /> | |
<TextView | |
android:id="@+id/result" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_centerInParent="true" | |
android:text="Resultado" /> | |
<EditText | |
android:id="@+id/edtFahrenheit" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_alignParentBottom="true" | |
android:layout_centerHorizontal="true" | |
android:layout_marginBottom="193dp" | |
android:ems="10" | |
android:inputType="textPersonName" /> | |
</RelativeLayout> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment