Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.apka;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- public class fliniowa extends Activity {
- EditText paramA;
- EditText paramB;
- EditText resultText;
- Button button1;
- float result = (float) 0;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.fliniowa);
- Button button = (Button) findViewById(R.id.button1);
- button.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- try{
- resultText = (EditText)findViewById(R.id.editText3);
- paramA = (EditText)findViewById(R.id.editText1);
- paramB = (EditText)findViewById(R.id.editText2);
- Float a = Float.parseFloat(paramA.getText().toString());
- Float b = Float.parseFloat(paramB.getText().toString());
- if (a != null && b != null){
- result = (float) -a / b;
- String finalResult=String.format("%.2f", result);
- resultText.setText(finalResult);
- if (resultText != null){
- }
- }
- }
- catch(Exception ex){
- Toast.makeText(fliniowa.this, "Podałeś błędne dane",
- Toast.LENGTH_LONG).show();
- }
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement