Mohanad Aljhani
unknown
plain_text
3 years ago
3.6 kB
9
Indexable
// main Activity
package com.example.myapplication
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
button.setOnClickListener {
var x = editTextNumber.text.toString()
var result = 0.0
if (x.toDouble() > 60000) {
var Al = AlertDialog.Builder(this)
Al.setTitle("Warnning")
Al.setMessage("Enter a reasonable capacity!!”)
Al . setPositiveButton ("?????"){ DialogInterface, which ->
Toast.makeText(
this,
"DONE",
Toast.LENGTH_SHORT
).show()
}
Al.setNeutralButton ("????") { DialogInterface, which ->
Toast.makeText(
this,
"OK",
Toast.LENGTH_SHORT
).show()
}
val alertDialog : AlertDialog = Al . create ()
alertDialog.show()
}
// textView.text="Enter a reasonable capacity !!"}
else {
result = (x.toDouble() * 1024 )
textView.text = result.toString()
val t = Toast.makeText(this, "DONE", Toast.LENGTH_SHORT)
t.show()
// t.setGravity(Gravity.START,200,200)
}
}
button2.setOnClickListener {
var x = editTextNumber.text.toString()
var result = 0.0
if (x.toDouble() > 60000)
textView.text = "Enter a reasonable capacity!!"
else {
result = (x.toDouble() * 1024)
textView.text = result.toString()
Toast.makeText(this, "DONE", Toast.LENGTH_SHORT).show()
}
}
button2.setOnClickListener {
val openURL = Intent(android.content.Intent.ACTION_VIEW) openURL.data = Uri.parse("https://www.unitconverters.net/“) startActivity(openURL)
}
}
}
// activity_main
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
android:background="#CCFFFF"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.075" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="56dp"
android:background="#F91313"
android:backgroundTint="#000000"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:strokeColor="#701010"
tools:layout_editor_absoluteX="158dp" />
</androidx.constraintlayout.widget.ConstraintLayout>Editor is loading...