Valyuta ayirboshlash uchun kichik dastur
Main oynadagi kod qismi:
package com.example.valyutaapp
import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import androidx.appcompat.app.AppCompatActivity
import androidx.core.widget.addTextChangedListener
import com.example.valyutaapp.databinding.ActivityMainBinding
class MainActivity : AppCompatActivity() {
lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
val dollor = 11420.0
val yevro = 12400.0
binding.edUSZ.addTextChangedListener {
object : TextWatcher {
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
}
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
binding.edDollor.setText(
"${
(binding.edUSZ.text.toString().toDoubleOrNull() ?: 0.0)
/ dollor
}"
)
binding.edYevro.setText(
"${
(binding.edUSZ.text.toString().toDoubleOrNull() ?: 0.0)
/ yevro
}"
)
}
override fun afterTextChanged(p0: Editable?) {
}
}
}
}
}
Activity_main layoutdagi kod:
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="16dp">
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/purple_700"
android:textStyle="italic|bold"
android:text="Valyuta ayirboshlash"
android:textSize="28sp"
android:layout_gravity="center"
android:layout_marginBottom="16dp"/>
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="22sp"
android:text="Summa:"
android:textColor="@color/black"
android:textStyle="bold"/>
android:id="@+id/edUSZ"
android:layout_width="match_parent"
android:layout_height="60dp"
android:text=""
android:textStyle="italic|normal"
android:textSize="20sp"
android:inputType="number"
android:textAlignment="textEnd"/>
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:textStyle="normal|italic"
android:text="$ (Dollor)"
android:textSize="20sp"
android:layout_marginTop="32dp"/>
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp">
android:id="@+id/edDollor"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawablePadding="4dp"
android:inputType="text"
android:background="@drawable/shape_login"
android:textColor="@color/black"
android:enabled="false"
android:textAlignment="textEnd"/>
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:textStyle="italic|normal"
android:text=" (Yevro)"
android:textSize="20sp"
android:layout_marginTop="16dp"/>
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp">
android:id="@+id/edYevro"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawablePadding="4dp"
android:inputType="text"
android:background="@drawable/shape_login"
android:textColor="@color/black"
android:enabled="false"
android:textAlignment="textEnd"/>
Dastur dizayni
Dostları ilə paylaş: |