-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathP33.kt
78 lines (64 loc) · 2.37 KB
/
P33.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package alpha.dex.one
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.view.View
import android.widget.Button
import android.widget.TextView
class Progress_BarEx : AppCompatActivity() {
private var i = 0
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_progress_bar_ex)
val pgsBar = findViewById<android.widget.ProgressBar>(R.id.pBar)
val pgsBar1 = findViewById<android.widget.ProgressBar>(R.id.pBarCircular)
val txtView = findViewById<TextView>(R.id.tView)
val btn = findViewById<Button>(R.id.btnShow)
val btnR = findViewById<Button>(R.id.btnReset)
val pauseth = findViewById<Button>(R.id.pauseThread)
var flag: Int
// pgsBar1.visibility = View.INVISIBLE
txtView.text = i.toString() + "/" + pgsBar.max
pauseth.setOnClickListener {
flag = 0
btn.text = "Resume"
}
btn.setOnClickListener {
flag = 1
pgsBar1.visibility = View.VISIBLE
i = pgsBar.progress
Thread {
while (i < 100) {
i += 1
if (flag == 0) {
pgsBar1.visibility = View.INVISIBLE
break
}
Handler(Looper.getMainLooper()).post {
pgsBar.progress = i
txtView.text = i.toString() + "/" + pgsBar.max
if (i == 100) { //Or pgsBar.max in place of 100
pgsBar1.visibility = View.INVISIBLE
// btn.text = "Start again"
// i = 0
// pgsBar.progress = i
}
}
try {
Thread.sleep(100)
} catch (e: InterruptedException) {
e.printStackTrace()
}
}
}.start()
}
btnR.setOnClickListener {
pgsBar.progress = 0
txtView.text = 0.toString() + "/" + pgsBar.max
pgsBar1.visibility = View.INVISIBLE
flag = 0
btn.text = "Start Again"
}
}
}