Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.support.v7.app.AlertDialog;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.EditText;
- 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 calcular(View view) {
- EditText tdolar = (EditText) findViewById(R.id.dolar);
- String sdolar = tdolar.getEditableText().toString();
- double ddolar = Double.parseDouble(sdolar);
- EditText treal = (EditText) findViewById(R.id.real);
- String sreal = treal.getEditableText().toString();
- double dreal = Double.parseDouble(sreal);
- double resultado = dreal/ddolar;
- TextView tresult = (TextView) findViewById(R.id.resultado);
- tresult.setText("$ " +String.format("%.2f",resultado));
- Toast.makeText(this,"$ " +String.format("%.2f",resultado),
- Toast.LENGTH_LONG).show();
- AlertDialog.Builder alerta = new AlertDialog.Builder(this);
- alerta.setTitle("Resultado");
- alerta.setMessage("$ " +String.format("%.2f",resultado));
- alerta.show();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement