This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun isTextMoreThan(editText: EditText, charNumber: Int): Boolean { | |
return if (editText.text.toString().length >= charNumber) { | |
editText.background = | |
ContextCompat.getDrawable(requireContext(), R.drawable.shape_edit_text) | |
editText.background.alpha = 180 | |
true | |
} else { | |
editText.background = ContextCompat.getDrawable( | |
requireContext(), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.livedatatest | |
import android.content.Intent | |
import android.os.Bundle | |
import android.util.Log | |
import android.widget.Button | |
import android.widget.EditText | |
import androidx.appcompat.app.AppCompatActivity | |
import androidx.core.widget.addTextChangedListener | |
import androidx.lifecycle.lifecycleScope |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.test | |
import androidx.appcompat.app.AppCompatActivity | |
import android.os.Bundle | |
import android.text.Editable | |
import android.text.TextWatcher | |
import com.example.test.databinding.ActivityMainBinding | |
class MainActivity : AppCompatActivity() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun String.formatIBAN(): String { | |
val iban = replace("\\s+".toRegex(), "").uppercase(Locale.getDefault()) | |
val maxLength = (iban.length * 1.25).roundToInt() | |
val result = StringBuilder(maxLength) | |
iban.forEachIndexed { index, c -> | |
when { | |
index > 0 && index % 4 == 0 -> result.append(" $c") | |
else -> result.append(c) | |
} | |
} |
OlderNewer