Let me try to explain the title.
I have a manufacturer TextView that is populated from MYSQL. When a manufacturer is selected it populates the Model TextView.
Now I want to add OTHER in each model, and when it is selected an EditText appears. Something like this:
-FORD
---Mustang
---Escape
---Other
-BMW
---X5
---Z4
---Other
Now whenever Other is selected, the EditText appears. If not, then it remains hidden.
The only way I got it working is by creating a field in mysql for each model. I am hoping there is a better approach.
Here is what I have done.
enter code here
<EditText
android:id="@+id/fordTextView"
android:layout_width="0dp"
android:layout_height="130px"
android:layout_marginStart="16dp"
android:visibility="gone"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:background="@drawable/custom_progress_bar_horizontal"
android:inputType="textPersonName"
android:paddingStart="@dimen/space_12"
android:hint="@string/item_entry__model"
android:paddingLeft="@dimen/space_12"
android:paddingTop="8dp"
android:paddingEnd="@dimen/space_12"
android:paddingRight="@dimen/space_12"
android:paddingBottom="8dp"
android:textAlignment="viewStart"
android:textColor="@color/text__primary"
android:textSize="14sp"
app:font='@{"normal"}'
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/plateNumTextView" />
<EditText
android:id="@+id/bmwTextView"
android:layout_width="0dp"
android:layout_height="130px"
android:layout_marginStart="16dp"
android:visibility="gone"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:background="@drawable/custom_progress_bar_horizontal"
android:inputType="textPersonName"
android:paddingStart="@dimen/space_12"
android:hint="@string/item_entry__model"
android:paddingLeft="@dimen/space_12"
android:paddingTop="8dp"
android:paddingEnd="@dimen/space_12"
android:paddingRight="@dimen/space_12"
android:paddingBottom="8dp"
android:textAlignment="viewStart"
android:textColor="@color/text__primary"
android:textSize="14sp"
app:font='@{"normal"}'
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/fordTextView" />
Here is is the java
if (itemViewModel.holder.model_id.equals(Constants.MODEL_FORD_OTHER)){
binding.get().fordTextView.setVisibility(View.VISIBLE);
binding.get().bmwTextView.setVisibility(View.GONE);
}
if (!itemViewModel.holder.model_id.equals(Constants.MODEL_FORD_OTHER)){
binding.get().fordTextView.setVisibility(View.GONE);
binding.get().fordTextView.setText("");
}
if (itemViewModel.holder.model_id.equals(Constants.MODEL_BMW_OTHER)){
binding.get().bmwTextView.setVisibility(View.VISIBLE);
binding.get().fordTextView.setVisibility(View.GONE);
}
if (!itemViewModel.holder.model_id.equals(Constants.MODEL_BMW_OTHER)){
binding.get().bmwTextView.setVisibility(View.GONE);
binding.get().bmwTextView.setText("");
}
Is there a way of doing this by using only one EditText?
question from:
https://stackoverflow.com/questions/65934211/add-hide-show-edittext 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…