Skip to content

Commit 542ece1

Browse files
Pawan DeshpandePawan Deshpande
authored andcommitted
Code Update
1 parent 477a69d commit 542ece1

File tree

2 files changed

+8
-22
lines changed

2 files changed

+8
-22
lines changed
Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
package com.tutorialsbuzz.androidcheckbox
22

3-
import androidx.appcompat.app.AppCompatActivity
43
import android.os.Bundle
5-
import android.util.TypedValue
6-
import android.view.ViewGroup
7-
import android.widget.CheckBox
84
import android.widget.Toast
9-
import androidx.core.view.setPadding
5+
import androidx.appcompat.app.AppCompatActivity
106
import kotlinx.android.synthetic.main.activity_main.*
117

128
class MainActivity : AppCompatActivity() {
@@ -15,19 +11,12 @@ class MainActivity : AppCompatActivity() {
1511
super.onCreate(savedInstanceState)
1612
setContentView(R.layout.activity_main)
1713

18-
1914
checkbox01.setOnCheckedChangeListener({ buttonView, isChecked ->
20-
Toast.makeText(this@MainActivity, "" + isChecked, Toast.LENGTH_SHORT).show()
15+
Toast.makeText(this@MainActivity, buttonView.text.toString()+ ": " + isChecked, Toast.LENGTH_SHORT).show()
2116
})
2217

23-
val checkBox = CheckBox(this)
24-
checkBox.layoutParams =
25-
ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
26-
checkBox.setText("CheckBox")
27-
checkBox.setPadding(24)
28-
checkBox.setTextSize(TypedValue.COMPLEX_UNIT_SP,15f)
29-
root.addView(checkBox)
30-
31-
18+
checkbox02.setOnCheckedChangeListener({ buttonView, isChecked ->
19+
Toast.makeText(this@MainActivity, buttonView.text.toString()+ ": " + isChecked, Toast.LENGTH_SHORT).show()
20+
})
3221
}
3322
}

app/src/main/res/layout/activity_main.xml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@
1010
tools:context=".MainActivity"
1111
android:id="@+id/root">
1212

13-
<!--android:layoutDirection="rtl"-->
1413
<CheckBox
1514
android:layout_width="wrap_content"
1615
android:layout_height="wrap_content"
1716
android:id="@+id/checkbox01"
18-
android:text="checkbox"
17+
android:text="checkbox 01"
1918
android:padding="10dp"
2019
android:textSize="16sp"
2120
android:textColor="#000"
@@ -24,10 +23,8 @@
2423
<CheckBox android:layout_width="wrap_content"
2524
android:layout_height="wrap_content"
2625
android:id="@+id/checkbox02"
27-
android:text="checkbox"
26+
android:text="checkbox 02"
2827
android:padding="10dp"
29-
android:textSize="16sp"
30-
android:theme="@style/CustomCheckbox01"
31-
/>
28+
android:textSize="16sp"/>
3229

3330
</LinearLayout>

0 commit comments

Comments
 (0)