Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.46 KB | None | 0 0
  1. package com.example.apka;
  2.  
  3. import android.app.Activity;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.widget.Button;
  7. import android.widget.EditText;
  8. public class fliniowa extends Activity {
  9.     EditText paramA;
  10.     EditText paramB;
  11.     EditText resultText;
  12.     Button button1;
  13.     float result = (float) 0;
  14.     @Override
  15.     protected void onCreate(Bundle savedInstanceState) {
  16.         super.onCreate(savedInstanceState);
  17.         setContentView(R.layout.fliniowa);             
  18.        
  19.         Button button = (Button) findViewById(R.id.button1);
  20.         button.setOnClickListener(new View.OnClickListener() {
  21.             public void onClick(View v) {
  22. try{
  23.                 resultText = (EditText)findViewById(R.id.editText3);
  24.                 paramA = (EditText)findViewById(R.id.editText1);
  25.                 paramB = (EditText)findViewById(R.id.editText2);
  26.                 Float a = Float.parseFloat(paramA.getText().toString());
  27.                 Float b = Float.parseFloat(paramB.getText().toString());
  28.                
  29.                 if (a != null && b != null){
  30.                     result = (float) -a / b;
  31.                     String finalResult=String.format("%.2f", result);
  32.                     resultText.setText(finalResult);                   
  33.                     if (resultText != null){
  34.                        
  35.                     }
  36.                 }  
  37.  
  38.  
  39. }
  40.  
  41. catch(Exception ex){
  42. Toast.makeText(fliniowa.this, "Podałeś błędne dane",
  43.    Toast.LENGTH_LONG).show();
  44. }
  45.             }
  46.         });
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement