Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.graphics.Color
- import androidx.appcompat.app.AppCompatActivity
- import android.os.Bundle
- import android.view.View
- import androidx.databinding.DataBindingUtil
- import com.example.upr5_binding.databinding.ActivityMainBinding
- class MainActivity : AppCompatActivity() {
- private lateinit var binding: ActivityMainBinding
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- //setContentView(R.layout.activity_main)
- //binding=DataBindingUtil.setContentView(this, R.layout.activity_main)
- binding = ActivityMainBinding.inflate(layoutInflater)
- setContentView(binding.root)
- //binding.textView.text="Ok"
- }
- fun chetno(view: View)
- {
- val chislo=binding.editTextNumber.text.toString().toInt()
- if( chislo%2==0) {
- binding.textView.text="Четно"
- binding.textView.setBackgroundColor(Color.GREEN)
- } else {
- binding.textView.text="Нечетно"
- binding.textView.setBackgroundColor(Color.YELLOW)
- }
- }
- fun btn_oper(view: View) {
- var tel=binding.editTextPhone.text.toString()
- var nomer="None"
- if( tel.startsWith("359")) tel=tel.replace("359","0")
- // 35988 -> 088
- if( tel.startsWith("088") ) {
- binding.imageView.setImageResource(R.drawable.a1)
- //nomer="A1-"+tel.substring(3)
- nomer=tel.replace("088","A1-")
- } else
- if( tel.startsWith("087")) {
- binding.imageView.setImageResource(R.drawable.vivacom)
- //nomer="Vivacom-"+tel.substring(3)
- nomer=tel.replace("087","Vivacom-")
- } else
- if( tel.startsWith("089")) {
- binding.imageView.setImageResource(R.drawable.yettel)
- //nomer="Yettel-"+tel.substring(3)
- nomer=tel.replace("089","Yettel-")
- } else
- binding.imageView.setImageResource(R.drawable.vapros)
- binding.textView.text=nomer
- }
- // Въведено число в EditText, в TextView да се изведат броят на цифрите с думи
- // 34 -> двуцифрено, 123 -> трицифрено ...
- fun btn_zad(view: View) {
- //1
- /*val ch=binding.editTextNumber.text.toString()
- if( ch.length==1 ) binding.textView.text="Едноцифрено"
- if( ch.length==2 ) binding.textView.text="Двуоцифрено"
- if( ch.length==3 ) binding.textView.text="Трицифрено"
- if( ch.length>3 ) binding.textView.text="Многоцифрено"*/
- //2
- /*val ch=binding.editTextNumber.text.toString()
- when(ch.length) {
- 1 ->binding.textView.text="Едноцифрено"
- 2->binding.textView.text="Двуоцифрено"
- 3->binding.textView.text="Трицифрено"
- else -> binding.textView.text="Многоцифрено"
- }*/
- //3
- val ch=binding.editTextNumber.text.toString()
- val vid= listOf("Многоцифрено","Едноцифрено","Двуоцифрено","Трицифрено")
- if(ch.length>3 ) binding.textView.text=vid[0]
- else binding.textView.text=vid[ch.length]
- }
- }
- <androidx.constraintlayout.widget.ConstraintLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context=".MainActivity">
- <TextView
- android:id="@+id/textView"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Hello World!"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintLeft_toLeftOf="parent"
- app:layout_constraintRight_toRightOf="parent"
- app:layout_constraintTop_toTopOf="parent" />
- <EditText
- android:id="@+id/editTextNumber"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginStart="37dp"
- android:layout_marginTop="27dp"
- android:layout_marginBottom="352dp"
- android:ems="10"
- android:inputType="number"
- app:layout_constraintBottom_toTopOf="@+id/imageView"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toTopOf="parent" />
- <Button
- android:id="@+id/button"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginStart="45dp"
- android:layout_marginTop="32dp"
- android:onClick="btn_zad"
- android:text="Button"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toBottomOf="@+id/editTextNumber" />
- <EditText
- android:id="@+id/editTextPhone"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginTop="17dp"
- android:ems="10"
- android:inputType="phone"
- app:layout_constraintEnd_toEndOf="@+id/button2"
- app:layout_constraintStart_toEndOf="@+id/button2"
- app:layout_constraintTop_toBottomOf="@+id/button" />
- <Button
- android:id="@+id/button2"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginStart="53dp"
- android:layout_marginTop="28dp"
- android:onClick="btn_oper"
- android:text="Operator"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toBottomOf="@+id/editTextPhone" />
- <ImageView
- android:id="@+id/imageView"
- android:layout_width="269dp"
- android:layout_height="0dp"
- android:layout_marginStart="53dp"
- android:layout_marginBottom="118dp"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toBottomOf="@+id/editTextNumber"
- app:srcCompat="@drawable/vapros" />
- </androidx.constraintlayout.widget.ConstraintLayout>
Add Comment
Please, Sign In to add comment