DjPractLelo 0.2.0__tar.gz → 0.2.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. djpractlelo-0.2.1/DjPractLelo/resources/AP_pract2.txt +104 -0
  2. djpractlelo-0.2.1/DjPractLelo/resources/AP_pract5UiComponent,fragment,Appbar.txt +141 -0
  3. djpractlelo-0.2.1/DjPractLelo/resources/Activity Life Cycle.txt +44 -0
  4. djpractlelo-0.2.1/DjPractLelo/resources/Broadcast receivers.txt +41 -0
  5. djpractlelo-0.2.1/DjPractLelo/resources/Database Programming with SQLite.txt +137 -0
  6. djpractlelo-0.2.1/DjPractLelo/resources/Dialog and Dialog Fragments.txt +122 -0
  7. djpractlelo-0.2.1/DjPractLelo/resources/Intents and EventListener,Adapters.txt +114 -0
  8. djpractlelo-0.2.1/DjPractLelo/resources/LayoutGridview with linear layout.txt +181 -0
  9. djpractlelo-0.2.1/DjPractLelo/resources/LayoutListview.txt +45 -0
  10. djpractlelo-0.2.1/DjPractLelo/resources/Menu.txt +132 -0
  11. djpractlelo-0.2.1/DjPractLelo/resources/Multiple Activity.txt +32 -0
  12. djpractlelo-0.2.1/DjPractLelo/resources/Multiple Fragment.txt +70 -0
  13. djpractlelo-0.2.1/DjPractLelo/resources/Notification.txt +64 -0
  14. djpractlelo-0.2.1/DjPractLelo/resources/Programming Media API and Teleph.txt +75 -0
  15. djpractlelo-0.2.1/DjPractLelo/resources/Programming Security and permiss.txt +37 -0
  16. djpractlelo-0.2.1/DjPractLelo/resources/Programming threads, handles and as.txt +44 -0
  17. djpractlelo-0.2.1/DjPractLelo/resources/Services.txt +37 -0
  18. djpractlelo-0.2.1/DjPractLelo/resources/b. Fragment Life Cycle.txt +51 -0
  19. {djpractlelo-0.2.0 → djpractlelo-0.2.1}/DjPractLelo.egg-info/PKG-INFO +1 -1
  20. djpractlelo-0.2.1/DjPractLelo.egg-info/SOURCES.txt +29 -0
  21. djpractlelo-0.2.1/MANIFEST.in +1 -0
  22. {djpractlelo-0.2.0 → djpractlelo-0.2.1}/PKG-INFO +1 -1
  23. {djpractlelo-0.2.0 → djpractlelo-0.2.1}/pyproject.toml +2 -3
  24. {djpractlelo-0.2.0 → djpractlelo-0.2.1}/setup.py +1 -1
  25. djpractlelo-0.2.0/DjPractLelo.egg-info/SOURCES.txt +0 -10
  26. {djpractlelo-0.2.0 → djpractlelo-0.2.1}/DjPractLelo/__init__.py +0 -0
  27. {djpractlelo-0.2.0 → djpractlelo-0.2.1}/DjPractLelo/resource_loader.py +0 -0
  28. {djpractlelo-0.2.0 → djpractlelo-0.2.1}/DjPractLelo.egg-info/dependency_links.txt +0 -0
  29. {djpractlelo-0.2.0 → djpractlelo-0.2.1}/DjPractLelo.egg-info/top_level.txt +0 -0
  30. {djpractlelo-0.2.0 → djpractlelo-0.2.1}/LICENCE +0 -0
  31. {djpractlelo-0.2.0 → djpractlelo-0.2.1}/README.md +0 -0
  32. {djpractlelo-0.2.0 → djpractlelo-0.2.1}/setup.cfg +0 -0
@@ -0,0 +1,104 @@
1
+ 1)Color
2
+ Code:
3
+ <?xml version="1.0" encoding="utf-8"?>
4
+ <resources>
5
+ <color name="purple_200">#FFBB86FC</color>
6
+ <color name="purple_500">#FF6200EE</color>
7
+ <color name="purple_700">#FF3700B3</color>
8
+ <color name="teal_200">#FF03DAC5</color>
9
+ <color name="teal_700">#FF018786</color>
10
+ <color name="black">#FF000000</color>
11
+ <color name="white">#FFFFFFFF</color>
12
+ <color name="bg_color">#F7F0B7</color>
13
+ </resources>
14
+
15
+ Xml file code:
16
+ <?xml version="1.0" encoding="utf-8"?>
17
+ <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
18
+ xmlns:app="http://schemas.android.com/apk/res-auto"
19
+ xmlns:tools="http://schemas.android.com/tools"
20
+ android:layout_width="match_parent"
21
+ android:layout_height="match_parent"
22
+ android:background="@color/bg_color"
23
+ tools:context=".MainActivity">
24
+ <Button
25
+ android:id="@+id/button"
26
+ android:layout_width="wrap_content"
27
+ android:layout_height="wrap_content"
28
+ android:backgroundTint="@color/black"
29
+ android:text="@string/xyz"
30
+ app:layout_constraintBottom_toBottomOf="parent"
31
+ app:layout_constraintEnd_toEndOf="parent"
32
+ app:layout_constraintHorizontal_bias="0.542"
33
+ app:layout_constraintStart_toStartOf="parent"
34
+ app:layout_constraintTop_toTopOf="parent"
35
+ app:layout_constraintVertical_bias="0.322" />
36
+
37
+
38
+
39
+ 2)String
40
+ Code:
41
+ <resources>
42
+ <string name="app_name">demo</string>
43
+ <string name="xyz">SRM COLLEGE</string>
44
+ </resources>
45
+
46
+
47
+
48
+ 4)Theme
49
+ Code:
50
+ <resources>
51
+ <style name="Theme.Demotheme" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
52
+ <!-- Primary brand color. -->
53
+ <item name="colorPrimary">@color/teal_200</item>
54
+ <item name="colorPrimaryVariant">@color/purple_200</item>
55
+ <item name="colorOnPrimary">@color/white</item>
56
+ <!-- Secondary brand color. -->
57
+ <item name="colorSecondary">@color/teal_700</item>
58
+ <item name="colorSecondaryVariant">@color/teal_200</item>
59
+ <item name="colorOnSecondary">@color/black</item>
60
+ <!-- Status bar color. -->
61
+ <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
62
+ <!-- Customize your theme here. -->
63
+ </style>
64
+ </resources>
65
+
66
+
67
+
68
+ 5)Theme using switch:
69
+ Code:
70
+ package com.example.demo
71
+ import ...
72
+ class MainActivity : AppCompatActivity() {
73
+ override fun onCreate(savedInstanceState: Bundle?) {
74
+ super.onCreate(savedInstanceState)
75
+ setContentView(R.layout.activity_main)
76
+ switch1.setOnCheckedChangeListener { compoundButton, b ->
77
+ if (b) {
78
+ AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
79
+ }
80
+ else { AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
81
+ }
82
+ }
83
+ }
84
+ }
85
+
86
+
87
+ 6)Dimension
88
+ Code:
89
+ <EditText
90
+ android:id="@+id/editTextTextPersonName"
91
+ android:layout_width="250dp"
92
+ android:layout_height="40dp"
93
+ android:ems="10"
94
+ android:inputType="textPersonName"
95
+ android:text="Name"
96
+ app:layout_constraintBottom_toBottomOf="parent"
97
+ app:layout_constraintEnd_toEndOf="parent"
98
+ app:layout_constraintHorizontal_bias="0.497"
99
+ app:layout_constraintStart_toStartOf="parent"
100
+ app:layout_constraintTop_toTopOf="parent"
101
+ app:layout_constraintVertical_bias="0.153" />
102
+
103
+
104
+
@@ -0,0 +1,141 @@
1
+ 1.AppBar
2
+ Code:
3
+ .kt file code
4
+ package com.example.my_fragment
5
+ import androidx.appcompat.app.AppCompatActivity
6
+ import android.os.Bundle
7
+ import android.view.Menu
8
+ import android.view.MenuItem
9
+ import android.widget.Toast
10
+ import kotlinx.android.synthetic.main.activity_main.*
11
+ class MainActivity : AppCompatActivity() {
12
+ override fun onCreate(savedInstanceState: Bundle?) {
13
+ super.onCreate(savedInstanceState)
14
+ setContentView(R.layout.activity_main)
15
+ setSupportActionBar(mytoolbar)
16
+ }
17
+ override fun onCreateOptionsMenu(menu: Menu?): Boolean {
18
+ super.onCreateOptionsMenu(menu)
19
+ menuInflater.inflate(R.menu.mymenu,menu)
20
+ return true
21
+ }
22
+ override fun onOptionsItemSelected(item: MenuItem): Boolean {
23
+ if(item.itemId==R.id.one){
24
+ Toast.makeText(this,"Folder is clicked",Toast.LENGTH_LONG).show()
25
+ }
26
+ if(item.itemId==R.id.two){
27
+ Toast.makeText(this,"Search is clicked",Toast.LENGTH_LONG).show()
28
+ }
29
+ if(item.itemId==R.id.s1){
30
+ Toast.makeText(this,"This is toast",Toast.LENGTH_LONG).show()
31
+ }
32
+ return super.onOptionsItemSelected(item)
33
+ }
34
+ }
35
+ .xml file code
36
+ <?xml version="1.0" encoding="utf-8"?>
37
+ <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
38
+ xmlns:app="http://schemas.android.com/apk/res-auto"
39
+ xmlns:tools="http://schemas.android.com/tools"
40
+ android:layout_width="match_parent"
41
+ android:layout_height="match_parent"
42
+ tools:context=".MainActivity">
43
+ <androidx.appcompat.widget.Toolbar
44
+ android:id="@+id/mytoolbar"
45
+ android:layout_width="match_parent"
46
+ android:layout_height="?attr/actionBarSize"
47
+ tools:ignore="MissingConstraints"
48
+ android:theme="@style/Theme.AppCompat.DayNight.DarkActionBar"
49
+ android:background="@color/teal_700"
50
+ app:titleTextColor="@color/white"
51
+ android:elevation="4dp"/>
52
+ </androidx.constraintlayout.widget.ConstraintLayout>
53
+ New .xml file code
54
+ <?xml version="1.0" encoding="utf-8"?>
55
+ <menu xmlns:android="http://schemas.android.com/apk/res/android"
56
+ xmlns:app="http://schemas.android.com/apk/res-auto">
57
+ <item android:id="@+id/one" android:title="folder" android:icon="@drawable/ic_baseline_folder_24" app:showAsAction="always"/>
58
+ <item android:id="@+id/two" android:title="search" android:icon="@drawable/ic_baseline_search_24" app:showAsAction="always"/>
59
+ <item android:id="@+id/main" android:title="Main Menu">
60
+ <menu>
61
+ <item android:id="@+id/s1" android:title="Toast"/>
62
+ <item android:id="@+id/s2" android:title="Exit"/>
63
+ </menu>
64
+ </item>
65
+ </menu>
66
+
67
+
68
+
69
+ 2.Fragments
70
+ Code:
71
+ package srm.it.fragmentdemo
72
+ import androidx.appcompat.app.AppCompatActivity
73
+ import android.os.Bundle
74
+ import kotlinx.android.synthetic.main.activity_main.*
75
+ class MainActivity : AppCompatActivity() {
76
+ override fun onCreate(savedInstanceState: Bundle?) {
77
+ super.onCreate(savedInstanceState)
78
+ setContentView(R.layout.activity_main)
79
+
80
+ var state=0
81
+ button.setOnClickListener {
82
+ if(state==0) {
83
+ supportFragmentManager.beginTransaction().replace(R.id.fragmentContainerView,first()).commit()
84
+ state=1
85
+ }
86
+ else
87
+ { supportFragmentManager.beginTransaction().replace(R.id.fragmentContainerView,second()).commit()
88
+ state=0
89
+ }
90
+ } } }
91
+
92
+
93
+
94
+ 3. UI Components
95
+ Code:
96
+ package sy.it.ui_component
97
+ import androidx.appcompat.app.AppCompatActivity
98
+ import android.os.Bundle
99
+ import android.widget.RadioButton
100
+ import android.widget.Toast
101
+ import androidx.appcompat.app.AlertDialog
102
+ import kotlinx.android.synthetic.main.activity_main.*
103
+
104
+ class MainActivity : AppCompatActivity() {
105
+ override fun onCreate(savedInstanceState: Bundle?) {
106
+ super.onCreate(savedInstanceState)
107
+ setContentView(R.layout.activity_main)
108
+
109
+ button.setOnClickListener {
110
+ var name=box1.text.toString()
111
+ var email= box2.text.toString()
112
+ var dob=box3.text.toString()
113
+ var pass=box4.text.toString()
114
+ var compass=box5.text.toString()
115
+
116
+ if(pass!=compass){
117
+ Toast.makeText(this,"Password does not match",Toast.LENGTH_SHORT).show()
118
+ }
119
+
120
+ var gen=radioGroup.checkedRadioButtonId
121
+ var gs=if (gen == -1) {
122
+ Toast.makeText(this, "Select gender", Toast.LENGTH_SHORT).show()
123
+ }
124
+ else {
125
+ findViewById<RadioButton>(gen).text.toString()
126
+ }
127
+
128
+ var term=if(checkBox.isChecked){
129
+ checkBox.text.toString()
130
+ }else{
131
+ Toast.makeText(this, "Please accept our terms and conditions", Toast.LENGTH_SHORT).show()
132
+ }
133
+ textView7.text = """
134
+ $name
135
+ $email
136
+ $dob
137
+ $pass
138
+ $gs
139
+ $term
140
+ """.trimIndent() }}}
141
+
@@ -0,0 +1,44 @@
1
+ A. Activity Life Cycle:
2
+ Code:
3
+ package example.it.prac2
4
+ import androidx.appcompat.app.AppCompatActivity
5
+ import android.os.Bundle
6
+ import android.widget.Toast
7
+ class MainActivity : AppCompatActivity()
8
+ {
9
+ override fun onCreate(savedInstanceState: Bundle?) {
10
+ super.onCreate(savedInstanceState)
11
+ Toast.makeText(this,"Oncreate",Toast.LENGTH_LONG).show()
12
+ setContentView(R.layout.activity_main)
13
+ }
14
+ override fun onPause()
15
+ {
16
+ Toast.makeText(this,"OnPause",Toast.LENGTH_LONG).show()
17
+ super.onPause()
18
+ }
19
+ override fun onStart()
20
+ {
21
+ Toast.makeText(this,"OnStart",Toast.LENGTH_LONG).show()
22
+ super.onStart()
23
+ }
24
+ override fun onRestart()
25
+ {
26
+ Toast.makeText(this,"OnRestart",Toast.LENGTH_LONG).show()
27
+ super.onRestart()
28
+ }
29
+ override fun onStop()
30
+ {
31
+ Toast.makeText(this,"OnStop",Toast.LENGTH_LONG).show()
32
+ super.onStop()
33
+ }
34
+ override fun onDestroy()
35
+ {
36
+ Toast.makeText(this,"OnDestroy",Toast.LENGTH_LONG).show()
37
+ super.onDestroy()
38
+ }
39
+ override fun onResume()
40
+ {
41
+ Toast.makeText(this,"OnResume",Toast.LENGTH_LONG).show()
42
+ super.onResume()
43
+ }
44
+ }
@@ -0,0 +1,41 @@
1
+ 3. Broadcast receivers
2
+ Code:
3
+ package com.tyit.broadcast
4
+
5
+ import android.content.BroadcastReceiver
6
+ import android.content.Context
7
+ import android.content.Intent
8
+ import android.content.IntentFilter
9
+ import androidx.appcompat.app.AppCompatActivity
10
+ import android.os.Bundle
11
+ import android.widget.Toast
12
+
13
+ class MainActivity : AppCompatActivity() {
14
+ var br =object :BroadcastReceiver(){
15
+ override fun onReceive(p0: Context?, p1: Intent?)
16
+ {
17
+ if (p1?.action==Intent.ACTION_AIRPLANE_MODE_CHANGED) {
18
+ var flag =p1.getBooleanExtra("state",false)
19
+ if (flag){
20
+ Toast.makeText(p0, "Airplane Mode ON", Toast.LENGTH_LONG).show()
21
+ }
22
+ else{
23
+ Toast.makeText(p0, "Airplane Mode OFF", Toast.LENGTH_LONG).show()
24
+ }
25
+ }
26
+ }
27
+ }
28
+ override fun onStart() {
29
+ super.onStart()
30
+ registerReceiver(br, IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED))
31
+ }
32
+ override fun onStop() {
33
+ super.onStop()
34
+ unregisterReceiver(br)
35
+ }
36
+ override fun onCreate(savedInstanceState: Bundle?) {
37
+ super.onCreate(savedInstanceState)
38
+ setContentView(R.layout.activity_main)
39
+ }
40
+ }
41
+
@@ -0,0 +1,137 @@
1
+ Database Programming with SQLite
2
+ Code:
3
+ Main.kt file:
4
+ package com.example.databaseconnection
5
+ import androidx.appcompat.app.AppCompatActivity
6
+ import android.os.Bundle
7
+ import android.widget.ArrayAdapter
8
+ import kotlinx.android.synthetic.main.activity_main.*
9
+ class MainActivity : AppCompatActivity() {
10
+ lateinit var db: MyDb
11
+ var oldId = ""
12
+
13
+ override fun onCreate(savedInstanceState: Bundle?) {
14
+ super.onCreate(savedInstanceState)
15
+ setContentView(R.layout.activity_main)
16
+ db = MyDb(this)
17
+ button.setOnClickListener {
18
+ db.increRec(data3.text.toString(), data1.text.toString(),data2.text.toString())
19
+ readData()
20
+ clearFields()
21
+ }
22
+
23
+ button2.setOnClickListener {
24
+ val newId = data3.text.toString()
25
+ val fn = data1.text.toString()
26
+ val ln = data2.text.toString()
27
+ db.updateRec(oldId, newId, fn, ln)
28
+ oldId = newId
29
+ readData()
30
+ clearFields()
31
+ }
32
+
33
+ lv.setOnItemClickListener { AdapterView, view, i, l ->
34
+ val item = lv.getItemAtPosition(i).toString()
35
+ val parts = item.split(" ")
36
+ oldId = parts[0]
37
+ data3.setText(parts[0])
38
+ data1.setText(parts[1])
39
+ data2.setText(parts[2])
40
+ }
41
+
42
+ lv.setOnItemLongClickListener {AdapterView, view, i, l ->
43
+ val item = lv.getItemAtPosition(i).toString()
44
+ val id = item.split(" ")[0]
45
+ db.deleteRec(id)
46
+ readData()
47
+ true
48
+ }
49
+ readData()
50
+ }
51
+
52
+ fun readData() {
53
+ val tdata = db.readData()
54
+ lv.adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, tdata)
55
+ }
56
+
57
+ fun clearFields() {
58
+ data3.setText("")
59
+ data1.setText("")
60
+ data2.setText("")
61
+ }
62
+ }
63
+
64
+ MyDB.kt file :
65
+ package com.example.databaseconnection
66
+ import android.content.ContentValues
67
+ import android.content.Context
68
+ import android.database.sqlite.SQLiteDatabase
69
+ import android.database.sqlite.SQLiteOpenHelper
70
+ import android.widget.Toast
71
+ class MyDb(var ctx: Context) : SQLiteOpenHelper(ctx, "TYIT2026", null, 2) {
72
+
73
+ override fun onCreate(db: SQLiteDatabase?) {
74
+ db?.execSQL(
75
+ "create table Student(" +
76
+ "id text primary key, " +
77
+ "fname text, " +
78
+ "lname text)"
79
+ )
80
+ }
81
+ override fun onUpgrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) {
82
+ db?.execSQL("DROP TABLE IF EXISTS Student")
83
+ onCreate(db)
84
+ }
85
+
86
+ fun increRec(id: String, fn: String, ln: String) {
87
+ val db = this.writableDatabase
88
+ val cv = ContentValues()
89
+ cv.put("id", id)
90
+ cv.put("fname", fn)
91
+ cv.put("lname", ln)
92
+ val res = db.insert("Student", null, cv)
93
+ if (res > 0)
94
+ Toast.makeText(ctx, "Record Inserted", Toast.LENGTH_LONG).show()
95
+ else
96
+ Toast.makeText(ctx, "ID Already Exists", Toast.LENGTH_LONG).show()
97
+ }
98
+
99
+ fun readData(): ArrayList<String> {
100
+ val db = this.readableDatabase
101
+ val data = ArrayList<String>()
102
+ val cursor = db.rawQuery("SELECT * FROM Student", null)
103
+ if (cursor.moveToFirst()) {
104
+ do {
105
+ data.add(cursor.getString(0) + " " +
106
+ cursor.getString(1) + " " +
107
+ cursor.getString(2))
108
+ } while (cursor.moveToNext())
109
+ }
110
+ cursor.close()
111
+ return data
112
+ }
113
+
114
+ fun deleteRec(id: String) {
115
+ val db = this.writableDatabase
116
+ val res = db.delete("Student", "id=?", arrayOf(id))
117
+ if (res > 0)
118
+ Toast.makeText(ctx, "Record Deleted", Toast.LENGTH_LONG).show()
119
+ else
120
+ Toast.makeText(ctx, "Delete Failed", Toast.LENGTH_LONG).show()
121
+ }
122
+
123
+ fun updateRec(oldId: String, newId: String, fn: String, ln: String) {
124
+ val db = this.writableDatabase
125
+ val cv = ContentValues()
126
+ cv.put("id", newId)
127
+ cv.put("fname", fn)
128
+ cv.put("lname", ln)
129
+ val res = db.update("Student", cv, "id=?", arrayOf(oldId))
130
+ if (res > 0)
131
+ Toast.makeText(ctx, "Record Updated", Toast.LENGTH_LONG).show()
132
+ else
133
+ Toast.makeText(ctx, "Update Failed", Toast.LENGTH_LONG).show()
134
+ }
135
+ }
136
+
137
+
@@ -0,0 +1,122 @@
1
+ 2)Dialog
2
+ Code:
3
+ package srm.it.dialog
4
+ import androidx.appcompat.app.AppCompatActivity
5
+ import android.os.Bundle
6
+ import android.widget.Toast
7
+ import androidx.appcompat.app.AlertDialog
8
+ import kotlinx.android.synthetic.main.activity_main.
9
+ class MainActivity : AppCompatActivity() {
10
+ override fun onCreate(savedInstanceState: Bundle?) {
11
+ super.onCreate(savedInstanceState)
12
+ setContentView(R.layout.activity_main)
13
+ button.setOnClickListener {
14
+ var mydialog=AlertDialog.Builder(this)
15
+ mydialog.setTitle("Hello")
16
+ mydialog.setMessage("do you want to exit ?...")
17
+ mydialog.setPositiveButton("Yes"){dialog,which->
18
+ Toast.makeText(this,"you click yes",Toast.LENGTH_LONG).show()
19
+ }
20
+ mydialog.setNegativeButton("No"){dialog,which->
21
+ Toast.makeText(this,"you click No",Toast.LENGTH_LONG).show()
22
+ }
23
+ mydialog.setNeutralButton("cancel"){dialog,which->
24
+ Toast.makeText(this,"you click No",Toast.LENGTH_LONG).show()
25
+ }
26
+ mydialog.show()
27
+ }
28
+ }
29
+ override fun onBackPressed() {
30
+ var mydialog=AlertDialog.Builder(this)
31
+ mydialog.setTitle("Hello")
32
+ mydialog.setMessage("do you want to exit ?...")
33
+ mydialog.setPositiveButton("Yes"){dialog,which->
34
+ Toast.makeText(this,"you click yes",Toast.LENGTH_LONG).show()
35
+ }
36
+ mydialog.setNegativeButton("No"){dialog,which->
37
+ Toast.makeText(this,"you click No",Toast.LENGTH_LONG).show()
38
+ }
39
+ mydialog.setNeutralButton("cancel"){dialog,which->
40
+ Toast.makeText(this,"you click No",Toast.LENGTH_LONG).show()
41
+ }
42
+ mydialog.show()
43
+ }
44
+ }
45
+
46
+
47
+ 3)Dialog fragments
48
+ Code:
49
+ .kt file code:
50
+ package com.example.dialogfragment
51
+ import androidx.appcompat.app.AppCompatActivity
52
+ import android.os.Bundle
53
+ import kotlinx.android.synthetic.main.activity_main.*
54
+ class MainActivity : AppCompatActivity() {
55
+ override fun onCreate(savedInstanceState: Bundle?) {
56
+ super.onCreate(savedInstanceState)
57
+ setContentView(R.layout.activity_main)
58
+ button.setOnClickListener {
59
+ var obj=Myclass()
60
+ obj.show(supportFragmentManager,"tyit")
61
+ }
62
+ }
63
+ }
64
+ .xml file code:
65
+ <?xml version="1.0" encoding="utf-8"?>
66
+ <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
67
+ xmlns:app="http://schemas.android.com/apk/res-auto"
68
+ xmlns:tools="http://schemas.android.com/tools"
69
+ android:layout_width="match_parent"
70
+ android:layout_height="match_parent"
71
+ tools:context=".MainActivity">
72
+ <Button
73
+ android:id="@+id/button"
74
+ android:layout_width="wrap_content"
75
+ android:layout_height="wrap_content"
76
+ android:text="Click"
77
+ app:layout_constraintBottom_toBottomOf="parent"
78
+ app:layout_constraintEnd_toEndOf="parent"
79
+ app:layout_constraintStart_toStartOf="parent"
80
+ app:layout_constraintTop_toTopOf="parent" />
81
+ </androidx.constraintlayout.widget.ConstraintLayout>
82
+ second .kt file code:
83
+ package com.example.dialogfragment
84
+ import android.os.Bundle
85
+ import android.view.LayoutInflater
86
+ import android.view.View
87
+ import android.view.ViewGroup
88
+ import android.widget.Toast
89
+ import androidx.fragment.app.DialogFragment
90
+ import kotlinx.android.synthetic.main.mylayout.view.*
91
+ class Myclass:DialogFragment() {
92
+ override fun onCreateView(
93
+ inflater: LayoutInflater,
94
+ container: ViewGroup?,
95
+ savedInstanceState: Bundle?
96
+ ): View? {
97
+ var s=inflater.inflate(R.layout.mylayout,container)
98
+ s.btn.setOnClickListener {
99
+ var d=s.text.text.toString()
100
+ Toast.makeText(context,"Welcome",Toast.LENGTH_LONG).show()
101
+ }
102
+ return s
103
+ }
104
+ }
105
+ second .xml file code:
106
+ <?xml version="1.0" encoding="utf-8"?>
107
+ <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
108
+ android:layout_width="match_parent"
109
+ android:layout_height="match_parent">
110
+ <EditText
111
+ android:layout_width="match_parent"
112
+ android:layout_height="wrap_content"
113
+ android:id="@+id/text"
114
+ android:hint="@string/app_name"/>
115
+ <Button
116
+ android:layout_width="wrap_content"
117
+ android:layout_height="wrap_content"
118
+ android:layout_below="@+id/text"
119
+ android:id="@+id/btn"
120
+ android:text="submit"/>
121
+ </RelativeLayout>
122
+