SHOW:
|
|
- or go back to the newest paste.
| 1 | package com.cig.fiz; | |
| 2 | ||
| 3 | import android.os.Bundle; | |
| 4 | import android.app.Activity; | |
| 5 | import android.view.View; | |
| 6 | import android.view.View.OnClickListener; | |
| 7 | import android.widget.Button; | |
| 8 | import android.widget.EditText; | |
| 9 | import android.widget.TextView; | |
| 10 | ||
| 11 | public class K extends Activity {
| |
| 12 | ||
| 13 | @Override | |
| 14 | protected void onCreate(Bundle savedInstanceState) {
| |
| 15 | super.onCreate(savedInstanceState); | |
| 16 | setContentView(R.layout.activity_k); | |
| 17 | - | Listener l = new Listener(); |
| 17 | + | EditText eT1 = (EditText) findViewById(R.id.eT1); |
| 18 | EditText eT2 = (EditText) findViewById(R.id.eT2); | |
| 19 | TextView tV = (TextView) findViewById(R.id.textView1); | |
| 20 | Listener l = new Listener(eT1,eT2,tV); | |
| 21 | // 1.gomb | |
| 22 | Button gen = (Button) findViewById(R.id.button1); | |
| 23 | gen.setOnClickListener(l); | |
| 24 | //2. gomb | |
| 25 | Button back = (Button) findViewById(R.id.button2); | |
| 26 | back.setOnClickListener(l); | |
| 27 | - | //ha az elso gomb |
| 27 | + | |
| 28 | public class Listener implements OnClickListener{
| |
| 29 | - | EditText eT1 = (EditText) findViewById(R.id.eT1); |
| 29 | + | EditText eT1; |
| 30 | - | EditText eT2 = (EditText) findViewById(R.id.eT2); |
| 30 | + | EditText eT2; |
| 31 | - | TextView tV = (TextView) findViewById(R.id.textView1); |
| 31 | + | TextView tV; |
| 32 | public Listener(EditText eT1,EditText eT2,TextView tV){
| |
| 33 | this.eT1 = eT1; | |
| 34 | this.eT2 = eT2; | |
| 35 | this.tV = tV; | |
| 36 | } | |
| 37 | @Override | |
| 38 | public void onClick(View v) {
| |
| 39 | //ha 1. gomb | |
| 40 | if(v.equals(findViewById(R.id.button1))){
| |
| 41 | ||
| 42 | //Hogyha ír valamit az editTextek-ben | |
| 43 | - | //ha a vissza gomb |
| 43 | + | |
| 44 | int f = Integer.parseInt(eT1.getText().toString()); | |
| 45 | int t = Integer.parseInt(eT2.getText().toString()); | |
| 46 | if(f != t){
| |
| 47 | int k = (f*t)/(t - f); | |
| 48 | tV.setText(k); | |
| 49 | } | |
| 50 | }else{
| |
| 51 | tV.setText("Vmi nem jó");
| |
| 52 | } | |
| 53 | //ha 2.gomb | |
| 54 | }else if(v.equals(findViewById(R.id.button2))){
| |
| 55 | finish(); | |
| 56 | } | |
| 57 | } | |
| 58 | ||
| 59 | } | |
| 60 | } |