D.Tech Academic
Deep Singh
Pages
Core Java
Web App
Spring
Hibernate
Kotlin
Android
Python
Flutter
Spring Boot
How to add two number in Kotlin
MainActivity.java
package com.example.deep.kotlindemo import android.support.v7.app.AppCompatActivity import android.os.Bundle import android.text.TextUtils import android.view.View import android.widget.EditText import android.widget.TextView import android.widget.Toast class MainActivity : AppCompatActivity() { lateinit var t1: EditText lateinit var t2: EditText override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) t1 = findViewById(R.id.first) t2 = findViewById(R.id.second) } fun submit(v: View) { if (TextUtils.isEmpty(t1.text.toString())) { t1.setError("Fill this field") } else if (TextUtils.isEmpty(t2.text.toString())) { t2.setError("Fill this field") } else { var i = Integer.parseInt(t1.text.toString()); var j = Integer.parseInt(t2.text.toString()); var c=i+j; Toast.makeText(this,"Output is : $c",Toast.LENGTH_LONG).show() } } }
activity_main.xml
manifest.xml
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment