I would like to display either 4 textView
s or just one editText
depending on the data that I receive from back-end
Here is my view as below
<LinearLayout 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:orientation="vertical">
<LinearLayout
android:id="@+id/groupOfFour"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/first"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<TextView
android:id="@+id/second"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<TextView
android:id="@+id/third"
android:layout_width="match_parent"
android:layout_height="match_parent"
t/>
<TextView
android:id="@+id/fourth"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
In my fragment I am doing like this
class MyFragment : Fragment(R.layout.my_fragment) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val backedData = getRemoteData()
if(backedData.hasFour()) {
editText.visibility = Visibility.GONE
// set the four text view
} else {
groupOfFour.visibility = Visibility.GONE
}
}
}
Is there any other way of achieving the same behavior?