Untitled

mail@pastecode.io avatar
unknown
kotlin
a year ago
2.5 kB
3
Indexable
Never
package com.example.ilkui

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.core.widget.addTextChangedListener
import com.example.ilkui.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity() {
    lateinit var binding: ActivityMainBinding
    var tvCounterLeftValue: Int = 0
    var tvCounterRightValue: Int = 0
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)

        //Başlangıçta sol ve sağ sayçların değerlerini sıfırladım
        binding.tvCounterLeft.text = tvCounterLeftValue.toString()
        binding.tvCounterRight.text = tvCounterRightValue.toString()
        binding.tvMergeResultValue.text = "00"
    }

    override fun onResume() {
        binding.btnIncreaseLeft.setOnClickListener {
            tvCounterLeftValue++
            binding.tvCounterLeft.text = tvCounterLeftValue.toString()
        }

        binding.btnDecreaseLeft.setOnClickListener {
            tvCounterLeftValue--
            binding.tvCounterLeft.text = tvCounterLeftValue.toString()
        }

        binding.btnIncreaseRight.setOnClickListener {
            tvCounterRightValue++
            binding.tvCounterRight.text = tvCounterRightValue.toString()
        }

        binding.btnDecreaseRight.setOnClickListener {
            tvCounterRightValue--
            binding.tvCounterRight.text = tvCounterRightValue.toString()
        }

        //Sürekli olarak tvCounterLeft'in değeri değişti mi diye bakar değiştiyse süslü
        //parantezlerin içerisinde yazan kodu çalıştırır.
        binding.tvCounterLeft.addTextChangedListener {
            //tvCounterLeft -> 5
            //tvCounterRight -> 3
            val mergeResult = binding.tvCounterLeft.text.toString() + binding.tvCounterRight.text.toString()
            //mergeResult -> 53
            binding.tvMergeResultValue.text = mergeResult
        }
        binding.tvCounterRight.addTextChangedListener {
            //tvCounterLeft -> 5
            //tvCounterRight -> 3
            val mergeResult = binding.tvCounterLeft.text.toString() + binding.tvCounterRight.text.toString()
            //mergeResult -> 53
            binding.tvMergeResultValue.text = mergeResult
        }

        super.onResume()
    }



}