I have the following list of checkboxes and TextInputLayouts
<CheckBox
android:text="#string/has_lession"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/hasLeassionCheckBox"
android:layout_marginTop="16dp" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent" android:layout_marginStart="32dp"
app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="32dp"
app:layout_constraintHorizontal_bias="1.0"
android:onClick="onCheckboxClicked"/>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent" android:layout_marginStart="32dp"
app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="32dp"
android:hint="#string/lesion_comments" app:layout_constraintHorizontal_bias="0.0"
android:layout_marginTop="16dp" app:layout_constraintTop_toBottomOf="#+id/hasHadLessionCheckBox"
android:visibility="gone" android:id="#+id/lesionCommentsField">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="false"/>
</com.google.android.material.textfield.TextInputLayout>
<CheckBox
android:text="#string/has_had_lession"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/hasHadLessionCheckBox" app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="32dp" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="32dp" android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="#+id/hasLeassionCheckBox"
android:onClick="onCheckboxClicked"/>
<CheckBox
android:text="#string/uses_tobaco"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/tobacoCheckBox" app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="32dp" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="32dp" android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="#+id/lesionCommentsField"
android:onClick="onCheckboxClicked"/>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent" android:layout_marginStart="32dp"
android:layout_marginEnd="32dp" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="16dp"
android:hint="#string/years_of_tobacco_use"
app:layout_constraintTop_toBottomOf="#+id/tobacoCheckBox" android:id="#+id/yearsOfTobacoUseField"
android:visibility="gone">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:inputType="number"/>
</com.google.android.material.textfield.TextInputLayout>
<CheckBox
android:text="#string/uses_alcohol"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/alcoholCheckbox" app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="32dp" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="32dp" android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="#+id/yearsOfTobacoUseField"
android:onClick="onCheckboxClicked"/>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/alcoholYearsField" app:layout_constraintStart_toEndOf="#+id/drinksPerWeek"
app:layout_constraintHorizontal_bias="0.5" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="32dp" android:layout_marginStart="8dp"
app:layout_constraintTop_toTopOf="#+id/drinksPerWeek"
app:layout_constraintBottom_toBottomOf="#+id/drinksPerWeek" android:hint="#string/years_alcohol_used"
android:visibility="gone">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/drinksPerWeek" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintHorizontal_bias="0.5" app:layout_constraintEnd_toStartOf="#+id/alcoholYearsField"
android:layout_marginStart="32dp" android:layout_marginEnd="8dp" android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="#+id/alcoholCheckbox" android:hint="#string/drinks_per_week"
android:visibility="gone">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:inputType="number"/>
</com.google.android.material.textfield.TextInputLayout>
<CheckBox
android:text="#string/history_of_cancer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/cancerCheckBox" app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="32dp" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="32dp" android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="#+id/drinksPerWeek"
android:onClick="onCheckboxClicked"/>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/cancerCountField" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintHorizontal_bias="0.5" app:layout_constraintEnd_toStartOf="#+id/cancerYearsField"
app:layout_constraintTop_toTopOf="#+id/cancerYearsField"
app:layout_constraintBottom_toBottomOf="#+id/cancerYearsField" android:layout_marginStart="32dp"
android:layout_marginEnd="8dp" android:visibility="gone"
android:hint="#string/cancer_count">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/cancerYearsField"
app:layout_constraintStart_toEndOf="#+id/cancerCountField" app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintEnd_toEndOf="parent" android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="#+id/cancerCheckBox" android:layout_marginStart="8dp"
android:layout_marginEnd="32dp" android:visibility="gone"
android:hint="#string/years_since_cancer">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"/>
</com.google.android.material.textfield.TextInputLayout>
<CheckBox
android:text="#string/history_of_oral_pain"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/oralPainCheckBox" android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="#+id/cancerCountField"
app:layout_constraintStart_toStartOf="parent" android:layout_marginStart="32dp"
app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="32dp"
android:onClick="onCheckboxClicked"/>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/painSeverityField" android:hint="#string/pain_severity"
app:layout_constraintStart_toEndOf="#+id/yearsOfOralPainField"
app:layout_constraintHorizontal_bias="0.5" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="16dp" app:layout_constraintTop_toBottomOf="#+id/oralPainCheckBox"
android:layout_marginStart="8dp" android:layout_marginEnd="32dp" android:visibility="gone">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/yearsOfOralPainField"
android:hint="#string/years_of_oral_pain" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintHorizontal_bias="0.5" app:layout_constraintEnd_toStartOf="#+id/painSeverityField"
app:layout_constraintTop_toTopOf="#+id/painSeverityField"
app:layout_constraintBottom_toBottomOf="#+id/painSeverityField" android:layout_marginStart="32dp"
android:layout_marginEnd="8dp" android:visibility="gone">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.button.MaterialButton
android:text="#string/next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/nextPatientButton" android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="#+id/painSeverityField" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="32dp"/>
</androidx.constraintlayout.widget.ConstraintLayout>
The TextInputLayouts are shown and hidden based on if cirtan checkboxes are clicked or not. Here is the code that handles that:
fun onCheckboxClicked(view: View) {
if (view is CheckBox) {
val checked: Boolean = view.isChecked
val test = view.id
when (view.id) {
R.id.hasLeassionCheckBox->{
if(checked){
lesionCommentsField.visibility = View.VISIBLE
}
else{
lesionCommentsField.visibility = View.GONE
}
}
R.id.tobacoCheckBox->{
if(checked){
yearsOfTobacoUseField.visibility = View.VISIBLE
}
else{
yearsOfTobacoUseField.visibility = View.GONE
}
}
R.id.alcoholCheckbox->{
if(checked){
drinksPerWeek.visibility = View.VISIBLE
alcoholYearsField.visibility = View.VISIBLE
Log.i("PATIENT ACTIVITY", "DRINKS PER WEEK VIEW: ${drinksPerWeek.visibility}")
}
else{
drinksPerWeek.visibility = View.GONE
alcoholYearsField.visibility = View.GONE
}
}
R.id.cancerCheckBox-> {
if (checked) {
cancerYearsField.visibility = View.VISIBLE
cancerCountField.visibility = View.VISIBLE
} else {
cancerYearsField.visibility = View.GONE
cancerCountField.visibility = View.GONE
}
}
R.id.oralPainCheckBox->{
if(checked){
yearsOfOralPainField.visibility = View.VISIBLE
painSeverityField.visibility = View.VISIBLE
}
else{
yearsOfOralPainField.visibility = View.GONE
painSeverityField.visibility = View.GONE
}
}
}
}
}
The way this is supposed to work is that certain TextInputLayouts are displayed when the user selects certain checkboxes. For example: if the user selects the has_lession checkbox, it is supposed to display the lesionCommentsField TextInputLayout.
The first time the user goes through this form, this code worked perfectly. For all the checkboxes and TextInputLayouts. The second time the user is on this form, the checkboxes that were clicked the last time around don't make their corresponding TextInputLayouts visible. For example: if the user selects the has_lession checkbox last time they used the form and selects the same checkbox this time around the lesionCommentsField is not displayed.
The other checkboxes that were not clicked in the previous use of the form work just fine, it is only the checkboxes that were used in previous use of the form that misbehaves.
The issue goes away when the app is restarted.
I have debugged and checked that the fields do get set to visible, they are just not displayed on the screen.
I have this inside a fragment and the checkbox code is in its parent activity. Not sure if this makes a difference.
How would I go about debugging and resolving this?
Editing my answer, I just understood multiple views can be visible at the same time.
Why are you not writing this separately for all the checkbox onCheckChange method instead of onClick?
hasLeassionCheckBox.setOnCheckedChangeListener { compoundButton, isChecked ->
if (isChecked) {
lesionCommentsField.visibility = View.VISIBLE
} else {
lesionCommentsField.visibility = View.GONE
}
}
Related
I am using TextInputLayout on Edit Profile screen and I wanted to update datas in that screen but when I used that, datas update to like
"com.google.android.material.textfield.TextInputLayout{9544eb3 V.ED..... ........ 93,232-931,455 #7f0a00d8 app:id/etEditName aid=1073741880}"
I will leave my codes.
ProfileFragment.kt
....
binding.btnEditProfile.setOnClickListener {
val dialog =
LayoutInflater.from(context).inflate(R.layout.edit_profile_dialog, null)
val builder = AlertDialog.Builder(context).setView(dialog).show()
builder.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
builder.setCancelable(true)
val etName = dialog.findViewById<TextInputLayout>(R.id.etEditName)
etName.editText?.setText(user.name)
val etSurname = dialog.findViewById<TextInputLayout>(R.id.etEditSurname)
etSurname.editText?.setText(user.surname)
val etWeight = dialog.findViewById<TextInputLayout>(R.id.etEditWeight)
etWeight.editText?.setText(user.weight)
val etHeight = dialog.findViewById<TextInputLayout>(R.id.etEditHeight)
etHeight.editText?.setText(user.height)
val etGoal = dialog.findViewById<TextInputLayout>(R.id.etEditGoal)
etGoal.editText?.setText(user.calorieGoal.toString())
dialog.findViewById<Button>(R.id.btnEditProfile).setOnClickListener {
if (etSurname.isNotEmpty() && etHeight.isNotEmpty() && etWeight.isNotEmpty() && etGoal.isNotEmpty())
dbUser.document(auth.currentUser?.email.toString())
.update(
mapOf(
"name" to etName.toString(),
"surname" to etSurname.toString(),
"height" to etHeight.toString(),
"weight" to etWeight.toString(),
)
)
.addOnSuccessListener {
Toast.makeText(context, "Updated!!", Toast.LENGTH_SHORT).show()
builder.dismiss()
} else {
Toast.makeText(context, "Fill in the fields!!", Toast.LENGTH_SHORT).show()
}
}
}
edit_dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="36dp"
android:background="#drawable/dialog_bg">
<TextView
android:id="#+id/txtEditProfile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:fontFamily="monospace"
android:text="#string/edit_profile"
android:textColor="#color/primaryDarkColor"
android:textSize="32sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/etEditName"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="24dp"
android:layout_marginTop="24dp"
android:hint="#string/enter_name"
android:maxLines="1"
app:errorEnabled="true"
app:hintTextColor="#color/gray"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/txtEditProfile">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="textPersonName"
android:textColorHint="#color/primaryDarkColor" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/etEditSurname"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="24dp"
android:layout_marginTop="24dp"
android:hint="#string/enter_surname"
android:maxLines="1"
app:errorEnabled="true"
app:hintTextColor="#color/gray"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/etEditName">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="textPersonName"
android:textColorHint="#color/primaryDarkColor" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/etEditWeight"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="110dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="24dp"
android:layout_marginTop="24dp"
android:focusableInTouchMode="false"
android:hint="#string/weight"
android:maxLines="1"
android:text=""
app:errorEnabled="true"
app:layout_constraintEnd_toStartOf="#+id/etEditHeight"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/etEditSurname">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:cursorVisible="false"
android:inputType="number"
android:textColorHint="#color/primaryDarkColor" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/etEditGoal"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="24dp"
android:layout_marginTop="8dp"
android:hint="#string/calorie_goal"
android:maxLines="1"
android:text=""
app:errorEnabled="true"
app:hintTextColor="#color/gray"
app:layout_constraintEnd_toStartOf="#+id/etEditHeight"
app:layout_constraintHorizontal_bias="0.508"
app:layout_constraintStart_toEndOf="#+id/etEditWeight"
app:layout_constraintTop_toBottomOf="#id/etEditHeight">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:cursorVisible="false"
android:inputType="number"
android:textColorHint="#color/primaryDarkColor" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/etEditHeight"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="110dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="24dp"
android:layout_marginTop="24dp"
android:hint="#string/height"
android:maxLines="1"
android:text=""
app:errorEnabled="true"
app:hintTextColor="#color/gray"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/etEditWeight"
app:layout_constraintTop_toBottomOf="#id/etEditSurname">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:cursorVisible="false"
android:inputType="number"
android:textColorHint="#color/primaryDarkColor" />
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="#+id/btnEditProfile"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_margin="24dp"
android:text="#string/submit"
android:textColor="#color/secondaryTextColor"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/etEditGoal" />
</androidx.constraintlayout.widget.ConstraintLayout>
Thanks for your helps :)
You are updating the TextInputLayout itself when you need to update the text in the EditText inside the TextInputLayout. So
Replace
"name" to etName.toString(),
"surname" to etSurname.toString(),
"height" to etHeight.toString(),
"weight" to etWeight.toString(),
With
"name" to etName.editText?.text.toString(),
"surname" to etSurname.editText?.text.toString(),
"height" to etHeight.editText?.text.toString(),
"weight" to etWeight.editText?.text.toString(),
This will update user data in the Edit Profile screen.
I'm creating a View Stub for my login screen, however I have a question. When I try to set an setOnClickListener on my login button in my viewstub_login.kt file, the button action won't go through. Do I need to change my extension on my Kotlin file, or do I need to put my setOnClickListener in the onStart() function? Thank you!
viewstub_login.xml
<?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="#BF090909">
<androidx.cardview.widget.CardView
android:id="#+id/loginCardView"
android:layout_width="0dp"
android:layout_height="300dp"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
app:cardBackgroundColor="#color/main_purple"
app:cardCornerRadius="8dp"
app:cardElevation="5dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/logoLoginImageView"
android:layout_width="90dp"
android:layout_height="35dp"
android:layout_marginTop="12dp"
android:contentDescription="#string/login_logo_image"
android:scaleType="fitXY"
android:src="#drawable/skedaddle_services_"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/emailTextInputLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="24dp"
android:textColorHint="#color/white"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/logoLoginImageView">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/emailInputTextView"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#drawable/textview_underlinr"
android:drawableStart="#drawable/outline_mail_white_24"
android:drawablePadding="5dp"
android:hint="#string/e_mail"
android:textColor="#color/white"
android:textColorHint="#color/white" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/passwordTextInputLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="24dp"
android:hint="#string/password"
android:textColorHint="#color/white"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/emailTextInputLayout"
app:passwordToggleEnabled="true"
app:passwordToggleTint="#color/white">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/passwordTextInputView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/textview_underlinr"
android:drawableStart="#drawable/outline_lock_white_24"
android:drawablePadding="5dp"
android:hint="#string/password"
android:inputType="textPassword"
android:textColor="#color/white"
android:textColorHint="#color/white" />
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="#+id/forgotPasswordButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:background="#android:color/transparent"
android:text="#string/forgot_password"
android:textAlignment="textEnd"
android:textAllCaps="false"
android:textColor="#color/white"
android:textSize="12sp"
android:textStyle="italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/passwordTextInputLayout" />
<Button
android:id="#+id/cancelButton"
android:layout_width="120dp"
android:layout_height="48dp"
android:background="#color/black"
android:text="#android:string/cancel"
android:textAllCaps="false"
android:textColor="#color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/secondLoginButton"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/forgotPasswordButton" />
<Button
android:id="#+id/secondLoginButton"
android:layout_width="120dp"
android:layout_height="48dp"
android:layout_marginStart="32dp"
android:background="#color/main_teal"
android:text="#string/log_in"
android:textAllCaps="false"
android:textColor="#FFFFFF"
app:layout_constraintBottom_toBottomOf="#+id/cancelButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/cancelButton"
app:layout_constraintTop_toTopOf="#+id/cancelButton"
tools:ignore="TextContrastCheck" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
viewstub_login.kt
class LoginViewStub : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.viewstub_login)
val emailTextView = findViewById<TextInputEditText>(R.id.emailInputTextView)
val passwordTextView = findViewById<TextInputEditText>(R.id.passwordTextInputView)
val forgetPasswordButton = findViewById<Button>(R.id.forgotPasswordButton)
val loginButton = findViewById<Button>(R.id.secondLoginButton)
val cancelButton = findViewById<Button>(R.id.cancelButton)
val emailText = emailTextView.text
val passwordText = passwordTextView.text
loginButton.setOnClickListener {
if (emailText.isEmpty(emailTextView.text) || passwordText.isEmpty(passwordTextView.text)) {
val dialogBuilder = AlertDialog.Builder(this)
dialogBuilder.setMessage("Please fill out all fields.").setCancelable(false).setPositiveButton("Okay", DialogInterface.OnClickListener {
dialog, id -> finish()
}).setNegativeButton("Cancel", DialogInterface.OnClickListener {
dialog, id -> dialog.cancel()
})
val alert = dialogBuilder.create()
alert.show()
}
}
cancelButton.setOnClickListener {
}
forgetPasswordButton.setOnClickListener {
}
}
}
private fun Boolean.isEmpty(str: CharSequence?): Boolean {
return str == null || str.length == 0
}
click listener is correct, but inside the block, your code is not correct
because emailText and passwordText is not null, as you have defined above, thus the if condition returning false and your code just going over it
I have a view that uses constraint layout. The view has an edit text and expects the soft keyboard input to show up. There are two buttons pinned to the bottom of the screen(Previous and Next). When the soft keyboard opens up, the two buttons hide behind the keyboard. However, I want the layout to resize so that the buttons are above the soft keyboard and not behind it.
I have the following in my manifest.
<activity
android:name=".activity.SomeActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize">
</activity>
I have looked at various other posts and tried a few different things like, adjustPan. I have set
android:fitsSystemWindows="true"
But both of them did not work.
My Constraint layout looks like this.
<?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:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorLibWhite"
android:focusable="true"
android:focusableInTouchMode="true"
tools:context=".ui.main.question.QuestionFragment">
<ProgressBar
android:id="#+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="0dp"
android:layout_height="8dp"
android:layout_marginTop="4dp"
android:background="#color/colorLibWhite"
android:indeterminate="false"
android:progressDrawable="#drawable/progress_bar_background"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:id="#+id/sectionHeader"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:background="#color/colorLibLighterGray"
android:ellipsize="end"
android:maxLines="2"
android:paddingStart="16dp"
android:paddingTop="8dp"
android:paddingEnd="16dp"
android:paddingBottom="8dp"
android:text="new section"
android:textColor="#color/colorLibGray"
android:textSize="12sp"
android:visibility="gone"
app:layout_constraintBottom_toTopOf="#+id/questionLabel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/progressBar"/>
<TextView
android:id="#+id/questionLabel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
android:text="#string/placeholder"
android:textAlignment="center"
app:layout_constraintBottom_toTopOf="#+id/inputContainerCL"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/sectionHeader"/>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/inputContainerCL"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="#+id/prevNextContainer"
app:layout_constraintTop_toBottomOf="#+id/questionLabel">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/inputContainer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
android:id="#+id/hintText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="12sp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:text="Hint text goes here"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/inputContainer"/>
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/prevNextContainer"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<Button
android:id="#+id/previous"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginBottom="16dp"
android:background="#drawable/primary_button"
android:text="#string/question_previous"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<Button
android:id="#+id/next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="16dp"
android:background="#drawable/primary_button"
android:text="#string/question_next"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
EditText is added programatically.
var editText = CustomEditText(context)
editText.apply {
id = View.generateViewId()
layoutParams = ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.MATCH_PARENT, ConstraintLayout.LayoutParams.WRAP_CONTENT)
setSingleLine(true)
imeOptions = EditorInfo.IME_ACTION_DONE
val questionType = question.validation?.type
if (questionType == Validation.Type.INTEGER) {
inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_SIGNED
} else if (questionType == Validation.Type.NUMBER) {
inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_SIGNED or InputType.TYPE_NUMBER_FLAG_DECIMAL
} else if (questionType == Validation.Type.MRN) {
inputType = InputType.TYPE_CLASS_NUMBER
filters = arrayOf(InputFilter.LengthFilter(9))
} else if (questionType == Validation.Type.ZIP_CODE) {
inputType = InputType.TYPE_CLASS_PHONE
filters = arrayOf(InputFilter.LengthFilter(10))
} else if (questionType == Validation.Type.PHONE) {
inputType = InputType.TYPE_CLASS_NUMBER
editText.setSelection(editText.text?.length!!)
editText.addTextChangedListener(PhoneFormatterTextWatcher(editText))
}
tag = TAG_FOCUS_FIRST
}
editText.setText(question.value ?: "")
if (question.validation?.type == Validation.Type.ZIP_CODE) {
editText.addTextChangedListener(ZipCodeTextWatcher(editText, question, updateCallback))
} else {
editText.addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(s: Editable?) {
//
}
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
//
}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
question.value = if (s != null && s.isNotBlank()) s.toString() else null
updateCallback()
}
}
)
}
editText.setOnEditorActionListener() { v, actionId, event ->
if (actionId == EditorInfo.IME_ACTION_DONE) {
doneCallback()
true
} else {
false
}
}
return editText
Here is the code that adds this view to input container
inputContainer.addView(editText)
Where is your EditText view?.I think you must learn about Constraint Layout. how ever you can try this xml layout code..
Add your styles for views.
<?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:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
tools:context=".ui.main.question.QuestionFragment">
<ProgressBar
android:id="#+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="411dp"
android:layout_height="7dp"
android:indeterminate="false"
android:progress="40"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/sectionHeader"
android:layout_width="99dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:maxLines="2"
android:paddingStart="16dp"
android:visibility="gone"
android:paddingTop="8dp"
android:paddingEnd="16dp"
android:paddingBottom="8dp"
android:text="new section"
android:textSize="12sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/progressBar" />
<TextView
android:id="#+id/questionLabel"
android:layout_width="379dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:text="questionLabel"
android:layout_marginRight="8dp"
android:textAlignment="center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/sectionHeader" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/inputContainerCL"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
app:layout_constraintBottom_toTopOf="#+id/prevNextContainer"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/questionLabel">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/inputContainer"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
app:layout_constraintBottom_toTopOf="#+id/hintText"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" >
<EditText
android:id="#+id/editText2"
android:layout_width="0dp"
android:layout_height="0dp"
android:ems="10"
android:gravity="top"
android:text="text"
android:inputType="textMultiLine"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
android:id="#+id/hintText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
android:text="Hint text goes here"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/prevNextContainer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<Button
android:id="#+id/previous"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginBottom="8dp"
android:text="question_previous"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="16dp"
android:text="question_next"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
this is the preview
I am trying to forward to a new layout based on the selection of a checkbox entry.
What would be the process in doing so?
<Button
android:id="#+id/button"
android:layout_width="127dp"
android:layout_height="38dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="PROCEED"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.502"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView"
app:layout_constraintVertical_bias="1.0" />
<CheckBox
android:id="#+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="108dp"
android:layout_marginStart="8dp"
android:layout_marginTop="116dp"
android:text="DOG"
android:textSize="30sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.434"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView" /> /
<CheckBox
android:id="#+id/checkBox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="108dp"
android:layout_marginStart="8dp"
android:layout_marginTop="12dp"
android:text="CAT"
android:textSize="30sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.424"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/checkBox2" />
</android.support.constraint.ConstraintLayout>
You implement OnCheckedChangeListener. More information here.
yourCheckBox.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener(){
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked) {
//launch activity, change fragment, load view,
}
else{
//whatever you want
}
}
});
Or you can set an attribute that change its value according to the checked checkbox and use that attribute in the implementation of what happens when you click the button.
So I have these values (Long and Double) in three textfields. They represent time, pace, and distance.
Now, to prevent user error I want to make them choose the values using numberPickers. I want to replace those textfields with those pickers.
This is what I have:
val time = timeTxtField as TextView
val distance = distanceTxtField as TextView
val pace = paceTxtField as TextView
var resetRunningBtn = clearBtn
val pickerMinutes = numberPicker as NumberPicker
val pickerSeconds = numberPickerSeconds as NumberPicker
pickerMinutes.minValue = 0
pickerMinutes.maxValue = 59
pickerMinutes.wrapSelectorWheel = false
pickerSeconds.minValue = 0
pickerSeconds.maxValue = 60
pickerSeconds.wrapSelectorWheel = false
calculateBtn.setOnClickListener {
when {
time.text.isEmpty() && (distance.text.isNotEmpty() && pace.text.isNotEmpty()) ->
calculatePace(null, distance.text.toString().toDouble(), pace.text.toString())
distance.text.isEmpty() && (time.text.isNotEmpty() && pace.text.isNotEmpty()) ->
calculatePace(time.text.toString(), null, pace.text.toString())
pace.text.isEmpty() && (time.text.isNotEmpty() && distance.text.isNotEmpty()) ->
calculatePace(time.text.toString(), distance.text.toString().toDouble(), null)
else -> {
Toast.makeText(this, "Please check fields",
Toast.LENGTH_SHORT).show()
}
}
}
As you can see I have the pickers set and all that. I tried to call something like .value but it didn't work.
This is my layout, so you can have a bit of understanding of the concept.
Any tips? :)
Thanks
EDIT XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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"
tools:context="com.reecreate.woderator2.Controller.RunningCalculatorActivity">
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="Running Pace Calculator"
android:textSize="24sp"
android:textStyle="bold"
android:inputType="numberDecimal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="#+id/distanceTxtField"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="28dp"
android:ems="10"
android:hint="distance..."
android:inputType="number|numberDecimal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.503"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/radioType" />
<EditText
android:id="#+id/timeTxtField"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:ems="10"
android:hint="time mm:ss"
android:inputType="time"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/distanceTxtField" />
<EditText
android:id="#+id/paceTxtField"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:ems="10"
android:hint="pace mm:ss 10:21"
android:inputType="time"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/timeTxtField" />
<RadioGroup
android:id="#+id/radioType"
android:layout_width="280dp"
android:layout_height="56dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="24dp"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView5">
<RadioButton
android:id="#+id/milesDistanceRadioBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="140dp"
android:layout_marginTop="16dp"
android:text="Miles"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toRightOf="#id/kmDistanceRadioBtn"
app:layout_constraintTop_toBottomOf="#id/textView5" />
<RadioButton
android:id="#+id/kmDistanceRadioBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:text="KM"
app:layout_constraintEnd_toStartOf="#+id/milesRadioBtn"
app:layout_constraintHorizontal_bias="0.694"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</RadioGroup>
<RadioGroup
android:id="#+id/paceRadioGroup"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="32dp"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.294"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/paceTxtField">
<RadioButton
android:id="#+id/milesPaceRadioBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="140dp"
android:layout_marginTop="16dp"
android:text="MILES PACE"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toRightOf="#id/kmDistanceRadioBtn"
app:layout_constraintTop_toTopOf="parent" />
<RadioButton
android:id="#+id/kmPaceRadioBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:text="KM PACE"
app:layout_constraintEnd_toStartOf="#+id/milesDistanceRadioBtn"
app:layout_constraintHorizontal_bias="0.694"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</RadioGroup>
<Button
android:id="#+id/calculateBtn"
style="#style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#color/colorAccent"
android:text="Calculate"
android:textColor="#android:color/background_light"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/result"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="24dp"
android:background="#drawable/border"
android:hint="Result"
android:textAlignment="center"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/paceRadioGroup" />
<Button
android:id="#+id/clearBtn"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="24dp"
android:background="#color/colorAccent"
android:text="CLEAR"
android:textColor="#android:color/background_light"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/result" />
<NumberPicker
android:id="#+id/numberPicker"
android:layout_width="64dp"
android:layout_height="119dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.407"
app:layout_constraintTop_toBottomOf="#+id/radioType" />
<NumberPicker
android:id="#+id/numberPickerSeconds"
android:layout_width="64dp"
android:layout_height="119dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/numberPicker" />
EDIT VALUE LISTENER
I added this, but not doing anything
var pickedValue: Int = pickerMinutes.value
time.setText(Integer.toString(pickedValue))
................
when {
pickerMinutes.isClickable -> time.setText(Integer.toString(pickedValue))
}
numberPicker.setOnValueChangedListener { pickerMinutes, oldVal, newVal ->
//store values in variable for use later
}
A few general Kotlin things to note: I see you are setting variables and casting the the number pickers. You don't need to do this. In Kotlin, with the correct import, something like: kotlinx.android.synthetic.main.my_layout_file.*, you can simply call the xml by its id without casting, like so: numberPicker. That goes for your other items as well, such as the TextViews.
The other thing is that you shouldn't have to call Integer.toString(pickedValue). You can just call pickedValue.toString().
Lastly, since I am unable to see exactly how you are testing the app, my suggestion would be to do the following:
Create variables to store the picker values:
var numPickerVal = 0;
var secondsPickerVal = 0;
Then set a change listener for each of the pickers:
numberPicker.setOnValueChangedListener { picker, oldVal, newVal ->
numPickerVal = newVal
}
numberPickerSeconds.setOnValueChangedListener { picker, oldVal, newVal ->
secondsPickerVal = newVal
}