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.
Related
I´m trying to get the text that was inserted into a EditText in the UI.
The UI looks like this. In a fragment the EditText for name has a default value "Hello".
After the user has entered a new value (for example "Hello2") I´d like to get the new value when the user clicks the Add Button.
But what I recive is still the default value "Hello".
My Code looks like this:
XML
<TextView
android:id="#+id/textView_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#color/backgroundtint_color"
android:text="Name"
android:textColor="#color/ntext_foreground"
android:textSize="#dimen/ntext_fontsize"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.075"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/textview_addingredient"
app:layout_constraintVertical_bias="0.050" />
JAVA Code in Fragment
public class AddIngredient extends Fragment{
//Controls
public EditText etN;
public EditText etK;
public EditText etF;
public EditText etC;
public EditText etP;
public TextView tv1;
//ViewModel
AddIngredientViewModel model;
#Override
public View onCreateView(
LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState
) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_addingredient, container, false);
// Get the values
tv1 = rootView.findViewById(R.id.textview_addingredient);
etN = rootView.findViewById(R.id.editText_name);
etK = rootView.findViewById(R.id.editText_kcal);
etF = rootView.findViewById(R.id.editText_fat);
etC = rootView.findViewById(R.id.editText_carbs);
etP = rootView.findViewById(R.id.editText_protein);
// Inflate the layout for this fragment
return rootView;
}
public void onViewCreated(#NonNull View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
view.findViewById(R.id.fragmentbutton_addingredient).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Get current values
String name = etN.getText().toString();
int kcal = Integer.parseInt(etK.getText().toString().trim());
int fat = Integer.parseInt(etF.getText().toString().trim());
int carbs = Integer.parseInt(etC.getText().toString().trim());
int protein = Integer.parseInt(etP.getText().toString().trim());
model = new ViewModelProvider(requireActivity()).get(AddIngredientViewModel .class);
Ingredient ingredient = new Ingredient(name, kcal, fat, carbs, protein){};
model.SaveIngredient(ingredient);
}
});
}
}
So has anyone an idea, what I have tho change to recive the current value? Thanks!
-- EDIT --
Entire 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="#color/screen_background"
tools:context=".fragments.AddIngredient">
<TextView
android:id="#+id/textview_addingredient"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="68dp"
android:text="Add Ingredient"
android:textColor="#color/headercolor"
android:textSize="#dimen/header_fontsize"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.126"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<!-- Name -->
<TextView
android:id="#+id/textView_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#color/backgroundtint_color"
android:text="Name"
android:textColor="#color/ntext_foreground"
android:textSize="#dimen/ntext_fontsize"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.075"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/textview_addingredient"
app:layout_constraintVertical_bias="0.050" />
<EditText
android:id="#+id/editText_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#color/backgroundtint_color"
android:ems="10"
android:inputType="textPersonName"
android:textColor="#color/ntext_foreground"
android:textSize="#dimen/ntext_fontsize"
android:text="Hello"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.157"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/textView_name"
app:layout_constraintVertical_bias="0.0" />
<!-- Kcal -->
<TextView
android:id="#+id/textView_kcal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#color/backgroundtint_color"
android:text="Kcal"
android:textColor="#color/ntext_foreground"
android:textSize="#dimen/ntext_fontsize"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.075"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/editText_name"
app:layout_constraintVertical_bias="0.050" />
<EditText
android:id="#+id/editText_kcal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#color/backgroundtint_color"
android:ems="10"
android:inputType="number"
android:text=""
android:textColor="#color/ntext_foreground"
android:textSize="#dimen/ntext_fontsize"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.157"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/textView_kcal"
app:layout_constraintVertical_bias="0.0" />
<!-- Fat -->
<TextView
android:id="#+id/textView_fat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#color/backgroundtint_color"
android:text="Fat"
android:textColor="#color/ntext_foreground"
android:textSize="#dimen/ntext_fontsize"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.075"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/editText_kcal"
app:layout_constraintVertical_bias="0.050" />
<EditText
android:id="#+id/editText_fat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#color/backgroundtint_color"
android:ems="10"
android:inputType="number"
android:text=""
android:textColor="#color/ntext_foreground"
android:textSize="#dimen/ntext_fontsize"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.157"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/textView_fat"
app:layout_constraintVertical_bias="0.0" />
<!-- Carbs -->
<TextView
android:id="#+id/textView_carbs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#color/backgroundtint_color"
android:text="Carbs"
android:textColor="#color/ntext_foreground"
android:textSize="#dimen/ntext_fontsize"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.075"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/editText_fat"
app:layout_constraintVertical_bias="0.050" />
<EditText
android:id="#+id/editText_carbs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#color/backgroundtint_color"
android:ems="10"
android:inputType="number"
android:text=""
android:textColor="#color/ntext_foreground"
android:textSize="#dimen/ntext_fontsize"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.157"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/textView_carbs"
app:layout_constraintVertical_bias="0.0" />
<!-- Protein -->
<TextView
android:id="#+id/textView_protein"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#color/backgroundtint_color"
android:text="Protein"
android:textColor="#color/ntext_foreground"
android:textSize="#dimen/ntext_fontsize"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.078"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/editText_carbs"
app:layout_constraintVertical_bias="0.052" />
<EditText
android:id="#+id/editText_protein"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#color/backgroundtint_color"
android:ems="10"
android:inputType="number"
android:text=""
android:textColor="#color/ntext_foreground"
android:textSize="#dimen/ntext_fontsize"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.157"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/textView_protein"
app:layout_constraintVertical_bias="0.0" />
<Button
android:id="#+id/fragmentbutton_addingredient"
android:layout_width="#dimen/button_width"
android:layout_height="#dimen/button_height"
android:background="#color/button_background"
android:gravity="left|center_vertical"
android:padding="20dp"
android:text="Add"
android:textColor="#color/button_foreground"
android:textSize="#dimen/button_fontsize"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.243"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/editText_protein"
app:layout_constraintVertical_bias="0.250" />
</androidx.constraintlayout.widget.ConstraintLayout>
Remove the default static text set to the editTextName field in your xml layout file. Due to this, the value is always getting stored as Hello. You shouldnt set text in EditTextview.
<EditText
android:id="#+id/editText_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#color/backgroundtint_color"
android:ems="10"
android:inputType="textPersonName"
android:textColor="#color/ntext_foreground"
android:textSize="#dimen/ntext_fontsize"
android:text="Hello" //Remove this line.
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
}
}
I am trying to get numeric user input on an EditText and I want it to be saved to an Integer Arraylist. I have code here that has numbers added programatically to an arraylist called number. I have also added Textviews to display the entire array and the first element of the array to see if it is good.
What I need help with is the syntax for saving user input into the EditText to the same Arraylist. I have searched this site and found nothing suitable.
I would also like to see the result in the Textview to make sure its working.
enter code hereI am trying to get numeric user input on an EditText and I want it to be saved to an Integer Arraylist. I have code here that has numbers added programatically to an arraylist called number. I have also added Textviews to display the entire array and the first element of the array to see if it is good.
What I need help with is the syntax for saving user input into the EditText to the same Arraylist.
I would also like to see the result in the Textview to make sure its working.
enter code here #Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayList<Integer> number = new ArrayList<Integer>();
look = (TextView)findViewById(R.id.tv1);
look2 = (TextView)findViewById(R.id.tv2);
setUIViews();
one.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
display1.setText("1");
}
});
two.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
display1.setText("2");
}
});
three.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
display1.setText("3");
}
});
number.add(1);
number.add(22);
number.add(45);
number.add(17);
number.add(0,7);
for (int i=0; i < number.size(); i++){
look2.setText(look2.getText() +" " + number.get(i) + " , ");
look.setText("First element is: "+number.get(0));
}
}
private void setUIViews (){
one = (Button)findViewById(R.id.btn1);
display1 = (EditText)findViewById(R.id.et1);
two = (Button)findViewById(R.id.btn2);
display1 = (EditText)findViewById(R.id.et1);
three = (Button)findViewById(R.id.btn3);
display1 = (EditText)findViewById(R.id.et1);
}
}
enter code here
enter code here<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=".MainActivity">
<EditText
android:id="#+id/et1"
android:layout_width="323dp"
android:layout_height="58dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="number"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.503"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.017" />
<Button
android:id="#+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="244dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="244dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:inputType="number"
android:text="1"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.522"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.212" />
<Button
android:id="#+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:inputType="number"
android:text="2"
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.212" />
<Button
android:id="#+id/btn3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:inputType="number"
android:text="3"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.921"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.212" />
<TextView
android:id="#+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.355" />
<TextView
android:id="#+id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.416" />
<Button
android:id="#+id/btnview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="View Arraylist"
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.798" />
enter code here
What I need help with is the syntax for saving user input into the EditText to the same Arraylist.
I think you mean this:
number.add(Integer.parseInt(display1.getText().toString()));
You Can handle EditText.AddonTextChangeListner and cast every 'char' to Int and add it to array and remove in case of deleting i think this will be efficient
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
}
I hope you can help me out with a problem. I tried to google it, and looked through the topics here, but was unable to find an answer.
I recently changed my layouts to ConstraintLayouts, and this have been working great so far. My problem however is i had some DialogFragments displaying a LinearLayout, and when i changed it to ConstraintLayout i only shows a faded overlay, but non of the elements in the layout. If i hardcode the width and height to something like 100dp, it will display that area. When i try match_parent or any other combination the same problem applies. I also tried setting the height and width to the device height and width but still with no luck.
In the onCreateView in my CreateWeddingMetadataFragment i have:
createButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d(TAG, "Show message dialog");
FragmentManager fm = getFragmentManager();
CreateWeddingMetadataDialogFragment welcomeMessageDialog = new CreateWeddingMetadataDialogFragment();
welcomeMessageDialog.show(fm, "metadate_fragment_dialog");
welcomeMessageDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
#Override
public void onDismiss(DialogInterface dialog) {
}
});
In my CreateWeddingMetadataFragmentDialog i have:
public class CreateWeddingMetadataDialogFragment extends DialogFragment{
private static final String TAG = CreateWeddingMetadataDialogFragment.class.getSimpleName();
public Button setupNow, setupLater;
public TextView mTest;
public ConstraintLayout parentLayout;
private DialogInterface.OnDismissListener onDismissListener;
public void setOnDismissListener(DialogInterface.OnDismissListener onDismissListener) {
this.onDismissListener = onDismissListener;
}
#Override
public void onDismiss(DialogInterface dialog) {
super.onDismiss(dialog);
if (onDismissListener != null) {
onDismissListener.onDismiss(dialog);
}
}
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(TAG, "I was called");
}
public CreateWeddingMetadataDialogFragment(){}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.create_welcome_message_view, container);
setupNow = (Button) view.findViewById(R.id.setupNowButton);
setupLater = (Button) view.findViewById(R.id.setupLaterButton);
mTest = (TextView) view.findViewById(R.id.welcomeMessageTitle);
parentLayout = (ConstraintLayout) view.findViewById(R.id.clWelcomeMessage);
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
int width = displayMetrics.widthPixels;
int height = displayMetrics.heightPixels;
parentLayout.setMinimumWidth(width);
parentLayout.setMinimumHeight(height);
mTest.setText("Test");
Log.d(TAG, "I was called onCreateView" + mTest);
setupNow.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Go to metadate page (Hide this dialog)
}
});
setupLater.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Go to signin page and create the wedding
}
});
return view;
}
}
That is with my current try of setting it to the device size.
And here is the create_welcome_message_view:
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:id="#+id/clWelcomeMessage">
<Button
android:text="DET GØR JEG SENERE"
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/setupLaterButton"
app:layout_constraintTop_toTopOf="#+id/guideline19"
app:layout_constraintBottom_toTopOf="#+id/guideline20"
android:layout_marginEnd="16dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginLeft="16dp"
android:background="#drawable/border"
android:layout_marginTop="2dp"
android:textColor="#color/colorPrimaryDark"/>
<Button
android:text="JEG VIL OPSÆTTE DEN NU"
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/setupNowButton"
app:layout_constraintTop_toTopOf="#+id/guideline12"
app:layout_constraintBottom_toTopOf="#+id/guideline19"
android:layout_marginEnd="16dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginLeft="16dp"
android:background="#color/colorPrimaryDark"
android:layout_marginBottom="2dp"
android:textColor="#color/White"/>
<TextView
android:text="EN PERSONLIG VELKOMST"
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/welcomeMessageTitle"
android:layout_marginTop="16dp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginEnd="32dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginRight="32dp"
android:layout_marginStart="32dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginLeft="32dp"
app:layout_constraintBottom_toTopOf="#+id/textView5"
android:layout_marginBottom="8dp"
android:textAlignment="center"
android:textSize="16sp"/>
<TextView
android:text="Nu skal I definere den velkomst, som jeres gæster får i appen. I kan skrive navnet på brylluppet, en hlsen og har mulighed at vælge et coverbillede"
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/textView5"
app:layout_constraintTop_toTopOf="#+id/guideline14"
android:layout_marginEnd="32dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginRight="32dp"
app:layout_constraintBottom_toTopOf="#+id/textView6"
android:layout_marginBottom="8dp"
android:layout_marginStart="32dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginLeft="32dp"
android:textAlignment="center"/>
<android.support.constraint.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/guideline12"
android:orientation="horizontal"
tools:layout_editor_absoluteY="204dp"
tools:layout_editor_absoluteX="0dp"
app:layout_constraintGuide_percent="0.4"/>
<TextView
android:text="Du vil altid kunne ændre din opsætning af velkomsten i din brugerprofil."
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/textView6"
app:layout_constraintBottom_toTopOf="#+id/guideline12"
android:layout_marginBottom="8dp"
app:layout_constraintTop_toTopOf="#+id/guideline15"
android:layout_marginStart="32dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginLeft="32dp"
android:layout_marginEnd="32dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginRight="32dp"
android:textAlignment="center"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintVertical_bias="1.0"/>
<android.support.constraint.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/guideline14"
android:orientation="horizontal"
tools:layout_editor_absoluteY="51dp"
tools:layout_editor_absoluteX="0dp"
app:layout_constraintGuide_percent="0.1"/>
<android.support.constraint.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/guideline15"
android:orientation="horizontal"
tools:layout_editor_absoluteY="153dp"
tools:layout_editor_absoluteX="0dp"
app:layout_constraintGuide_percent="0.3"/>
<android.support.constraint.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/guideline19"
android:orientation="horizontal"
tools:layout_editor_absoluteY="255dp"
tools:layout_editor_absoluteX="0dp"
app:layout_constraintGuide_percent="0.5"/>
<android.support.constraint.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/guideline20"
android:orientation="horizontal"
tools:layout_editor_absoluteY="305dp"
tools:layout_editor_absoluteX="0dp"
app:layout_constraintGuide_percent="0.6"/>
</android.support.constraint.ConstraintLayout>
If you need any additional information let me know, and thanks in advance.
This works fine - check out
1) Its good practice to arrange items in order where possible in XML too as visualized. Just to easily comprehend later.
2) Its looks every other element is constraining itself to others height and width and mostly resulting in 0 height and width. Watch out for 0dp and wrap_content on LayoutParams.
3) Take support of Vertical Bias too.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
android:id="#+id/clWelcomeMessage"
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="wrap_content"
android:orientation="vertical">
<android.support.constraint.Guideline
android:id="#+id/guideline_ver_16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="#dimen/sixteenDP"/>
<android.support.constraint.Guideline
android:id="#+id/guideline_ver_end_16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_end="#dimen/sixteenDP"/>
<TextView
android:id="#+id/welcomeMessageTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="32dp"
android:layout_marginLeft="32dp"
android:layout_marginRight="32dp"
android:layout_marginStart="32dp"
android:layout_marginTop="16dp"
android:text="EN PERSONLIG VELKOMST"
android:textAlignment="center"
android:textSize="16sp"
app:layout_constraintBottom_toTopOf="#+id/textView5"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<android.support.constraint.Guideline
android:id="#+id/guideline1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.1"/>
<android.support.constraint.Guideline
android:id="#+id/guideline2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.2"/>
<TextView
android:id="#+id/textView5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:text="Nu skal I definere den velkomst, som jeres gæster får i
appen.
I kan skrive navnet på brylluppet, en hlsen og har mulighed at vælge et
coverbillede"
android:textAlignment="center"
app:layout_constraintEnd_toEndOf="#+id/guideline_ver_end_16"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="#+id/guideline_ver_16"
app:layout_constraintTop_toBottomOf="#+id/guideline2"/>
<TextView
android:id="#+id/textView6"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:text="Du vil altid kunne ændre din opsætning af velkomsten i din
brugerprofil."
android:textAlignment="center"
app:layout_constraintBottom_toTopOf="#+id/setupNowButton"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="#+id/guideline_ver_16"
app:layout_constraintRight_toRightOf="#+id/guideline_ver_end_16"
app:layout_constraintTop_toBottomOf="#+id/textView5"/>
<Button
android:id="#+id/setupNowButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:background="#color/colorPrimaryDark"
android:text="JEG VIL OPSÆTTE DEN NU"
android:textColor="#color/White"
app:layout_constraintBottom_toTopOf="#+id/setupLaterButton"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView6"
app:layout_constraintVertical_bias="1.0"/>
<android.support.constraint.Guideline
android:id="#+id/guideline6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.6"/>
<Button
android:id="#+id/setupLaterButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
android:text="DET GØR JEG SENERE"
android:background="#drawable/border"
android:textColor="#color/colorPrimaryDark"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="#+id/guideline6"
app:layout_constraintVertical_bias="1.0"/>
</android.support.constraint.ConstraintLayout>
Also, app:layout_constraintWidth_default="wrap" (with width set to 0dp). If set, the widget will have the same size as if using wrap_content, but will be limited by constraints (i.e. it won't expand beyond them).
Supporting resource