Xona ma'lumotlar bazasidan foydalanish Nazariy qismi


O’quv markazining 1 ta kurs narxi bilish uchun mobil ilova


Download 0.71 Mb.
bet2/2
Sana18.06.2023
Hajmi0.71 Mb.
#1592244
1   2
Bog'liq
Sanjarbek Nabiyev

O’quv markazining 1 ta kurs narxi bilish uchun mobil ilova:

Main oynadagi kod qismi:


package com.example.sanjarapp

import androidx.appcompat.app.AppCompatActivity


import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import com.example.sanjarapp.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity() {


lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
var kursSumma=0.0
var kursSumma2=0.0

val kunlik3 = 13.0


val kunlik2 = 9.0
binding.edKursSumma.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) {
if (p0.toString()!=""){
kursSumma=(p0.toString().toDoubleOrNull()?:0.0)/kunlik2
kursSumma2=(p0.toString().toDoubleOrNull()?:0.0)/kunlik3
val text="%.2f".format(kursSumma)
val text2="%.2f".format(kursSumma2)
binding.ed2Kun.setText(text)
binding.edD3Kun.setText(text2)
}
}
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="match_parent"
android:orientation="vertical">
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="Bir oylik kurs narxi"
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/edKursSumma"
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="1 hafta 3 kun"
android:textSize="20sp"
android:layout_marginTop="32dp"/>

android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_marginTop="8dp">
android:id="@+id/edD3Kun"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawablePadding="4dp"
android:inputType="text"
android:textColor="@color/black"
android:enabled="false"
android:background="@null"
android:hint="Kunlik narxi:"
android:textAlignment="textEnd"/>

android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:textStyle="italic|normal"
android:text="1 haftada 2 kun"
android:textSize="20sp"
android:layout_marginTop="16dp"/>

android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_marginTop="8dp">
android:id="@+id/ed2Kun"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawablePadding="4dp"
android:inputType="text"
android:background="@null"
android:textColor="@color/black"
android:enabled="false"
android:textAlignment="textEnd"
android:hint="Kunlik narxi:"/>





Dastur dizayni:


Dastur ko’rinishi:






Download 0.71 Mb.

Do'stlaringiz bilan baham:
1   2




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling