Adım 1 − Android Studio’da yeni bir proje oluşturun, File ⇒ New ⇒ New Project‘e gidin ve yeni bir proje oluşturmak için gerekli tüm ayrıntıları doldurun.
Adım 2 − Aşağıdaki kodu res/layout/activity_main.xml dosyasına ekleyin.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="4dp"> <TextView android:id="@+id/textSonuc" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_marginTop="70dp" android:background="#008080" android:padding="5dp" android:text="Tasarım Kodlama" android:textColor="#fff" android:textSize="24sp" android:textStyle="bold" /> <EditText android:id="@+id/editSayi1" android:inputType="number" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerInParent="true" /> <EditText android:id="@+id/editSayi2" android:inputType="number" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/editSayi1" android:layout_centerInParent="true" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/editSayi2" android:layout_centerInParent="true" android:onClick="btnHesapla" android:text="Tıkla" /> </RelativeLayout> |
Adım 3 − Aşağıdaki kodu src/MainActivity.kt‘ye ekleyin
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | package com.example.tasarimkodlama import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.view.View import android.widget.EditText import android.widget.TextView import org.json.JSONException import org.json.JSONObject class MainActivity : AppCompatActivity() { //Eklenen Kodlar. Değişken tanımlandı. lateinit var editSayi1:EditText lateinit var editSayi2:EditText lateinit var textSonuc:TextView override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) } fun btnHesapla(view:View){ editSayi1= findViewById(R.id.editSayi1) editSayi2= findViewById(R.id.editSayi2) textSonuc= findViewById(R.id.textSonuc) var sonuc = editSayi1.text.toString().toInt() + editSayi2.text.toString().toInt() textSonuc.setText(sonuc.toString()) } } |
Çıktı:












2 Yorum