Checkbox disappears when spinner item is selected in Fragment - android

I have a fragment in which I have a spinner and checkbox.
The layout file need_help_fragment_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#color/all_fragment_background"
android:clickable="true"
android:focusable="true">
<androidx.constraintlayout.widget.Guideline
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/parent_top"
app:layout_constraintGuide_percent="0"
android:orientation="horizontal"/>
<androidx.constraintlayout.widget.Guideline
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/parent_bottom"
app:layout_constraintGuide_percent="1"
android:orientation="horizontal"/>
<androidx.constraintlayout.widget.Guideline
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/parent_left"
android:orientation="vertical"
app:layout_constraintGuide_percent="0"/>
<androidx.constraintlayout.widget.Guideline
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/parent_right"
android:orientation="vertical"
app:layout_constraintGuide_percent="1"/>
<androidx.constraintlayout.widget.Guideline
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/top_title_bottom"
app:layout_constraintGuide_percent=".25"
android:orientation="horizontal"/>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#+id/top_title_bottom"
app:layout_constraintEnd_toStartOf="#+id/parent_right"
app:layout_constraintStart_toEndOf="#+id/parent_left"
app:layout_constraintTop_toBottomOf="#+id/parent_top">
<androidx.constraintlayout.widget.Guideline
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/text_view_top"
app:layout_constraintGuide_percent="0"
android:orientation="horizontal"/>
<androidx.constraintlayout.widget.Guideline
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/text_view_bottom"
app:layout_constraintGuide_percent="1"
android:orientation="horizontal"/>
<androidx.constraintlayout.widget.Guideline
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/text_view_left"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.07"/>
<androidx.constraintlayout.widget.Guideline
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/text_view_right"
android:orientation="vertical"
app:layout_constraintGuide_percent=".93"/>
<TextView
android:text="#string/need_help_header_text"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:id="#+id/title_header_text_view"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="#+id/text_view_top"
app:layout_constraintBottom_toTopOf="#+id/text_view_bottom"
app:layout_constraintStart_toEndOf="#+id/text_view_left"
app:layout_constraintEnd_toStartOf="#+id/text_view_right"
android:textColor="#color/all_text_color"
android:textSize="18sp"
android:gravity="center">
</TextView>
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.Guideline
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/mid_content_bottom_guide"
app:layout_constraintGuide_percent=".8"
android:orientation="horizontal"/>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="#+id/top_title_bottom"
app:layout_constraintBottom_toTopOf="#+id/mid_content_bottom_guide"
app:layout_constraintStart_toEndOf="#+id/parent_left"
app:layout_constraintEnd_toStartOf="#+id/parent_right">
<androidx.constraintlayout.widget.Guideline
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/mid_content_top"
app:layout_constraintGuide_percent="0"
android:orientation="horizontal"/>
<androidx.constraintlayout.widget.Guideline
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/mid_content_bottom"
app:layout_constraintGuide_percent="1"
android:orientation="horizontal"/>
<androidx.constraintlayout.widget.Guideline
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/mid_content_left"
android:orientation="vertical"
app:layout_constraintGuide_percent=".07"/>
<androidx.constraintlayout.widget.Guideline
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/mid_content_right"
android:orientation="vertical"
app:layout_constraintGuide_percent=".93"/>
<androidx.constraintlayout.widget.Guideline
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/spinner_bottom"
app:layout_constraintGuide_percent=".2"
android:orientation="horizontal"/>
<androidx.appcompat.widget.AppCompatSpinner
android:background="#null"
app:layout_constraintTop_toBottomOf="#+id/mid_content_top"
app:layout_constraintBottom_toTopOf="#+id/spinner_bottom"
app:layout_constraintStart_toEndOf="#+id/mid_content_left"
app:layout_constraintEnd_toStartOf="#+id/mid_content_right"
android:id="#+id/spinner_view"
android:layout_width="0dp"
android:layout_height="0dp"
android:gravity="center_horizontal | bottom"
android:text="3 Seconds"
android:textColor="#color/all_text_color"
android:textSize="22sp" />
<androidx.constraintlayout.widget.Guideline
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/checkbox_top"
app:layout_constraintGuide_percent=".4"
android:orientation="horizontal"/>
<androidx.constraintlayout.widget.Guideline
android:layout_width="0dp"
android:layout_height="0dp"
android:id="#+id/checkbox_bottom"
app:layout_constraintGuide_percent=".6"
android:orientation="horizontal"/>
<CheckBox
android:layout_width="0dp"
android:layout_height="0dp"
android:text="Remove timing, Auto Mode"
app:layout_constraintTop_toBottomOf="#+id/checkbox_top"
app:layout_constraintBottom_toTopOf="#+id/checkbox_bottom"
app:layout_constraintStart_toEndOf="#+id/mid_content_left"
app:layout_constraintEnd_toStartOf="#+id/mid_content_right"
android:layoutDirection="rtl"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:textSize="18sp"
android:textColor="#color/all_text_color"
android:id="#+id/remove_timing_auto_mode_check_box"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Code in fragment:
class NeedHelpFragment: Fragment(), View.OnClickListener {
lateinit var homeActivity : MainActivity
var check_box: CheckBox? = null
var spinner_view: Spinner? = null
lateinit var timeSpinnerList: ArrayList<String>
lateinit var timeSpinnerAdapter: ArrayAdapter<String>
override fun onAttach(context: Context) {
super.onAttach(context)
if(context is MainActivity)
homeActivity = context
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
var v : View = inflater.inflate(R.layout.need_help_fragment_layout, container, false)
check_box = v.findViewById<CheckBox>(R.id.check_box)
timeSpinnerList = ArrayList()
for(i in 0..10)
timeSpinnerList.add("$i seconds")
timeSpinnerAdapter = ArrayAdapter(homeActivity, android.R.layout.simple_spinner_dropdown_item, timeSpinnerList)
spinner_view = v.findViewById<Spinner>(R.id.spinner_view)
spinner_view!!.adapter = timeSpinnerAdapter
return v
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
}
override fun onClick(view: View?) {
when(view!!.id){
}
}
}
The color code:
<color name="colorPrimary">#6200EE</color>
<color name="colorPrimaryDark">#3700B3</color>
<color name="colorAccent">#03DAC5</color>
<color name="all_text_color">#6F6F6F</color>
<color name="all_fragment_background">#F8F8F8</color>
When anything is not selected it is fine:
When an item is selected from the spinner, the checkbox disappears:
There is nothing else in the layout file. Just the constraint layout and the guidelines for the checkbox and spinner. The spinner and the checkbox are initialized in the onCreateView of the fragment. The checkbox disappears when I select any item from the spinner. Please help.

I think the problem is about your setting value about constraintLayout options like :
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/spinner_view"
app:layout_constraintBottom_toBottomOf="parent"
I think that was wrong in some cases.
Then for simple example i removed guidelines and i solved it.
You can use this approach and add your guidelines.
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/all_fragment_background"
android:clickable="true"
android:focusable="true">
<TextView
android:id="#+id/title_header_text_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="120dp"
android:gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="HEAD"
android:textColor="#color/all_text_color"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.AppCompatSpinner
android:id="#+id/spinner_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:background="#null"
android:gravity="center_horizontal|bottom"
android:text="3 Seconds"
android:textColor="#color/all_text_color"
android:textSize="22sp"
app:layout_constraintBottom_toTopOf="#+id/remove_timing_auto_mode_check_box"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/title_header_text_view" />
<CheckBox
android:id="#+id/remove_timing_auto_mode_check_box"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layoutDirection="rtl"
android:paddingLeft="10dp"
android:text="Remove timing, Auto Mode"
android:textColor="#color/all_text_color"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/spinner_view" />
</androidx.constraintlayout.widget.ConstraintLayout>

Related

Trying to Achieve Exposed Drop-Down Menu in Android

I am Trying to Achieve the Exposed Drop-Down Menu in Android I have tried this one but can't identify where I went wrong.
DropDown_item.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.textview.MaterialTextView
android:id="#+id/textViewFeelings"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="15dp"
android:text="TextView"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold" />
</androidx.appcompat.widget.LinearLayoutCompat>
BottomSheetDialogConnectWifiFragment.kt
class BottomSheetDialogConnectWifiFragment : BottomSheetDialogFragment() {
private lateinit var _binding: FragmentBottomSheetDialogConnectWifiBinding
private val items = listOf("Material", "Design", "Components", "Android")
private lateinit var ActivityContext: Context
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
override fun onAttach(context: Context) {
ActivityContext = context
super.onAttach(context)
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = FragmentBottomSheetDialogConnectWifiBinding.inflate(inflater, container, false)
return _binding.root
//
// val arrayAdapter = ArrayAdapter(_binding.root.context, R.layout.dropdown_item, items)
// _binding.autoCompleteTextFieldSsidType.setAdapter(arrayAdapter)
_binding.autoCompleteTextFieldSsidType.apply {
setAdapter(
ArrayAdapter(
ActivityContext,
R.layout.dropdown_item,
items
)
)
}
}
companion object {
const val TAG = "CustomBottomSheetDialogFragment"
}
}
fragment_bottom_sheet_dialog_connect_wifi
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView 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:padding="10dp"
tools:context=".Fragments.BottomSheetDialogConnectWifiFragment">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp">
<androidx.cardview.widget.CardView
android:layout_width="100dp"
android:layout_height="2dp"
android:layout_centerHorizontal="true"
android:elevation="10dp"
android:foregroundGravity="center_vertical"
app:cardBackgroundColor="#color/black"
app:cardCornerRadius="100dp">
<!--YOUR CONTENT-->
</androidx.cardview.widget.CardView>
<com.google.android.material.textview.MaterialTextView
android:id="#+id/idTVCourseTracks"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Add Network"
android:textAlignment="center"
android:textColor="#color/black"
android:textSize="15sp" />
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/tilSsid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/idTVCourseTracks"
android:keyboardNavigationCluster="true">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter The SSID" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textFieldSsidType"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/tilSsid"
android:layout_marginTop="12dp">
<AutoCompleteTextView
android:id="#+id/autoCompleteTextFieldSsidType"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Enter The SSID"
android:inputType="none" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textFieldPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textFieldSsidType"
android:layout_marginTop="12dp">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.button.MaterialButton
android:id="#+id/idBtnDismiss"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textFieldPassword"
android:layout_marginTop="12dp"
android:text="Connect"
android:textAllCaps="false"
android:theme="#style/ShapeAppearanceOverlay.Material3.Button" />
</RelativeLayout>
</ScrollView>
</com.google.android.material.card.MaterialCardView>
I Created An bottomSheet in Android/kotlin and trying to solve this cant understood where i missing some thing to
i have try with .Apply{}Method And also with the normally but both of them not worked for me

Fatal Exception: java.lang.VerifyError Verifier rejected class due to bad method DataBinderMapperImpl.internalGetViewDataBinding

I'm getting this error on Android 5x but i don't know what it could be the problem. I'm getting the error on the file FragmentDataNewjourneyBindingImpl. So i tracked and the file that is using the FragmentDataNewJourneyBinding is AuthenticationFragment. So it could be either my xml has something wrong or my fragment has.
This is my 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"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="viewModel"
type="br.com.gabriel.novajornada.security.auth.AuthenticationViewModel" />
<variable
name="constantes"
type="br.com.gabriel.novajornada.constants.ConstantsKt" />
</data>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/include"
android:fitsSystemWindows="true">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/constraintLayout11"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView"
style="#style/bo_texto_regular"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/margin"
android:layout_marginEnd="#dimen/margin"
android:gravity="center_horizontal"
android:lineSpacingExtra="4sp"
android:text="#string/fill_data_title_new_journey"
android:textColor="#1a1b1a"
android:textSize="24sp"
app:layout_constraintTop_toTopOf="#id/constraintLayout11" />
<TextView
android:id="#+id/textView98"
style="#style/bo_texto_regular"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/margin"
android:layout_marginTop="#dimen/margin_small"
android:layout_marginEnd="#dimen/margin"
android:gravity="center_horizontal"
android:lineSpacingExtra="6sp"
android:text="#string/fill_data_subtitle"
android:textColor="#4a4b4a"
android:textSize="16sp"
app:layout_constraintTop_toBottomOf="#id/textView"
tools:layout_editor_absoluteX="0dp" />
<br.com.original.common.components.BOTextInputLayout
android:id="#+id/text_input_cpf"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/margin"
android:layout_marginTop="19dp"
android:layout_marginRight="#dimen/margin"
android:hint="#string/identifier_field_title"
android:theme="#style/TextInputLayoutTheme.ClearButton"
app:errorEnabled="true"
app:errorTextAppearance="#style/MyProfile.Error"
app:hintTextAppearance="#style/TextLabel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView98">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/identifier"
style="#style/TextInputEditTextTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:text="#={viewModel.credentials.cpf}"
app:mask="#{ `###.###.###-##` }" />
</br.com.original.common.components.BOTextInputLayout>
<br.com.original.common.components.BOTextInputLayout
android:id="#+id/text_input_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/margin"
android:layout_marginRight="#dimen/margin"
android:hint="#string/name_field"
android:inputType="textNoSuggestions|textVisiblePassword"
android:theme="#style/TextInputLayoutTheme.ClearButton"
app:errorEnabled="true"
app:errorTextAppearance="#style/MyProfile.Error"
app:hintTextAppearance="#style/TextLabel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/text_input_cpf">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/name"
style="#style/TextInputEditTextTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ âãàáäêèéëîìíïôòóõöùúüñçÂÃÀÁÄÊÈÉËÎÌÍÏÔÒÓÕÖÙÚÜÑÇ"
android:inputType="textNoSuggestions|textVisiblePassword"
android:maxLength="#{constantes.NAMES_MAX_LENGTH}"
android:text="#={viewModel.credentials.name}" />
</br.com.original.common.components.BOTextInputLayout>
<br.com.original.common.components.BOTextInputLayout
android:id="#+id/text_input_phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/margin"
android:layout_marginRight="#dimen/margin"
android:clipChildren="false"
android:hint="#string/cellphone_ddd_field_title"
android:theme="#style/TextInputLayoutTheme.ClearButton"
app:errorTextAppearance="#style/MyProfile.Error"
app:hintTextAppearance="#style/TextLabel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/text_input_name">
<androidx.appcompat.widget.AppCompatEditText
android:id="#+id/phone"
style="#style/TextInputEditTextTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:text="#={viewModel.credentials.phoneNumber}"
app:mask="#{ `(##) #####-####` }" />
</br.com.original.common.components.BOTextInputLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginBottom="#dimen/margin"
app:layout_constraintBottom_toTopOf="#+id/btnConfirm"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/text_input_phone"
app:layout_constraintVertical_bias="1.0">
<TextView
android:id="#+id/politicas"
style="#style/seja_subtitle_h3_regular"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingStart="#dimen/margin"
android:paddingEnd="#dimen/margin"
android:text="#string/politicas_header_new_journey"
android:textSize="#dimen/text_small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:layout_editor_absoluteY="4dp" />
<TextView
android:id="#+id/openPoliticas"
style="#style/seja_subtitle_h3_regular"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingStart="#dimen/margin"
android:paddingTop="2pt"
android:paddingEnd="#dimen/margin"
android:text="#string/privacy_policy_new_journey"
android:textSize="#dimen/text_small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/politicas" />
</androidx.constraintlayout.widget.ConstraintLayout>
<Button
android:id="#+id/btnConfirm"
style="#style/seja_button_bordeless"
android:layout_width="match_parent"
android:layout_height="#dimen/button_height_seja"
android:layout_marginStart="#dimen/margin"
android:layout_marginTop="#dimen/margin"
android:layout_marginEnd="#dimen/margin"
android:enabled="#{identifier.text.length() == 14 && phone.text.length() == 15 && name.text.length() > 2}"
android:text="#string/continue_button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<include
android:id="#+id/include"
layout="#layout/seja_bar_layout_newjourney_center" />
<br.com.original.bank.novajornada.common.component.BOStateView
android:id="#+id/stateView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
app:msv_errorView="#layout/seja_error_view_newjourney"
app:msv_loadingView="#layout/seja_loading_view_newjourney" />
</RelativeLayout>
</layout>
This is AuthenticationFragment.kt. I put only the part of the bindingView declaration because i think it's more important:
#ExperimentalCoroutinesApi
class AuthenticationFragment : NavigationFragment() {
val viewModel: AuthenticationViewModel by viewModel()
lateinit var bindingView: FragmentDataNewjourneyBinding
lateinit var formValidate: FormValidate
private val novaJornadaActivity: NovaJornadaActivity by lazy { activity as NovaJornadaActivity }
private val management: TagManagement by inject()
#ExperimentalCoroutinesApi
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
bindingView = DataBindingUtil.inflate<FragmentDataNewjourneyBinding>(inflater, R.layout.fragment_data_newjourney, container, false)
.apply {
lifecycleOwner = this#AuthenticationFragment
viewModel = this#AuthenticationFragment.viewModel
}
viewModel.checkUserPromoted((activity as NovaJornadaActivity).userPromoted)
return bindingView.root
}
Is there something wrong with my implementation? I will be glad for anyone for trying to help me

Add and Remove Views in Android Dynamically in Kotlin

I modified my code by referring to the "https://www.tutorialspoint.com/add-and-remove-views-in-android-dynamically-in-kotlin". There was no error in my code, but the view added when running in the app was not visible. I have no idea what the problem is. Please help me!!
Activity to which the view is added
package com.akj.callback
import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.widget.*
import com.akj.callback.databinding.ActivitySearchSubject2Binding
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.activity_search_subject_2.*
import kotlinx.android.synthetic.main.activity_search_subject_2.to_go_check
import kotlinx.android.synthetic.main.choiced_subject_list.*
import java.util.*
class search_subject_2 : AppCompatActivity() {
lateinit var binding3:ActivitySearchSubject2Binding
private var parentLinearLayout: LinearLayout? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_search_subject_2)
parentLinearLayout = findViewById(R.id.parent_linear_layout)
binding3= ActivitySearchSubject2Binding.inflate(layoutInflater)
setContentView(binding3.root)
userList3.onItemClickListener= AdapterView.OnItemClickListener{
parent, view, position, id ->
//parent?.getItemAtPosition(position).toString()
onAddField()
}
val user = arrayOf("abc", "bcd", "cde", "def", "efg")
val userAdapter: ArrayAdapter<String> = ArrayAdapter(
this,android.R.layout.simple_list_item_1,user)
to_go_check.setOnClickListener {
val intent6=Intent(this#search_subject_2,checkthesetting::class.java)
startActivity(intent6)
}
binding3.searchView3.setOnQueryTextListener(object :androidx.appcompat.widget.SearchView.OnQueryTextListener{
override fun onQueryTextSubmit(query: String?): Boolean {
binding3.searchView3.clearFocus()
if(user.contains(query)){
userAdapter.filter.filter(query)
}
return false
}
override fun onQueryTextChange(newText: String?): Boolean {
if(newText==""){
}
else{
binding3.userList3.adapter=userAdapter
userAdapter.filter.filter(newText)
}
return false
}
})
}
fun onDelete(view: View) {
parentLinearLayout!!.removeView(view.parent as View)
}
fun onAddField() {
val inflater =
getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val rowView: View = inflater.inflate(R.layout.choiced_subject_list, null)
parentLinearLayout!!.addView(rowView, parentLinearLayout!!.childCount - 1)
Toast.makeText(applicationContext,"fdsvkgjh", Toast.LENGTH_SHORT).show()
}
}
choiced_subject_list.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal">
<TextView
android:id="#+id/number_edit_text"
android:text="title_fdskhdsffsd"
android:textColor="#color/black"
android:textSize="30dp"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="5"
android:inputType="phone"
/>
<Button
android:id="#+id/delete_button"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="1"
android:background="#android:drawable/ic_delete"
android:onClick="onDelete" />
</LinearLayout>
activity_search_subject_2.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"
tools:context=".search_subject_2">
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guideline1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.04" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guideline2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.94" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guideline3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.03" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guideline4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.97" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guideline5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.06" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guideline6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.11" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guideline7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.87" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guideline8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.5" />
<androidx.appcompat.widget.SearchView
android:id="#+id/searchView3"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#drawable/coner_search_bar"
android:theme="#style/AppSearchView"
app:layout_constraintBottom_toTopOf="#id/guideline6"
app:layout_constraintEnd_toEndOf="#id/guideline4"
app:layout_constraintStart_toStartOf="#id/guideline3"
app:layout_constraintTop_toBottomOf="#id/guideline5"
app:queryHint="강좌 검색"
app:iconifiedByDefault="false"
/>
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/to_go_check"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintStart_toEndOf="#id/guideline3"
app:layout_constraintEnd_toStartOf="#id/guideline4"
app:layout_constraintTop_toBottomOf="#id/guideline1"
app:layout_constraintBottom_toTopOf="#id/guideline2"
app:layout_constraintVertical_bias="0.98"
android:text="확인"
android:textColor="#FFF"
android:textSize="20dp"
android:background="#drawable/coner_search_bar"
android:stateListAnimator="#null"
/>
<HorizontalScrollView
android:id="#+id/scrollView"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:scrollbars="none"
app:layout_constraintBottom_toTopOf="#+id/to_go_check"
app:layout_constraintEnd_toStartOf="#id/guideline4"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="#id/guideline3"
>
<LinearLayout
android:id="#+id/linear_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/njklsfd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:background="#drawable/search_subject_bar"
android:stateListAnimator="#null"
android:text="전공검색" />
<androidx.appcompat.widget.AppCompatButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:background="#drawable/search_subject_bar"
android:stateListAnimator="#null"
android:text="교양검색" />
<androidx.appcompat.widget.AppCompatButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:background="#drawable/search_subject_bar"
android:stateListAnimator="#null"
android:text="교수검색" />
<androidx.appcompat.widget.AppCompatButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:background="#drawable/search_subject_bar"
android:stateListAnimator="#null"
android:text="정렬" />
<androidx.appcompat.widget.AppCompatButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:background="#drawable/search_subject_bar"
android:stateListAnimator="#null"
android:text="학점:3" />
<androidx.appcompat.widget.AppCompatButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:background="#drawable/search_subject_bar"
android:stateListAnimator="#null"
android:text="학점:2" />
<androidx.appcompat.widget.AppCompatButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:background="#drawable/search_subject_bar"
android:text="학점:1"
/>
</LinearLayout>
</HorizontalScrollView>
<ListView
android:id="#+id/userList3"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#+id/guideline8"
app:layout_constraintEnd_toStartOf="#+id/guideline4"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="#id/guideline3"
app:layout_constraintTop_toTopOf="#+id/guideline6"
app:layout_constraintVertical_bias="0.0" />
<LinearLayout
android:orientation="vertical"
android:id="#+id/parent_linear_layout"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="7dp"
android:layout_marginBottom="7dp"
app:layout_constraintBottom_toTopOf="#id/scrollView"
app:layout_constraintEnd_toStartOf="#+id/guideline4"
app:layout_constraintStart_toEndOf="#id/guideline3"
app:layout_constraintTop_toBottomOf="#id/guideline8" />
</androidx.constraintlayout.widget.ConstraintLayout>
Try this:
val inflater = getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val rowView: View = inflater.inflate(R.layout.row_child_view, null, false)
Mainview.removeView(rowView)

Disable certain part of fragment for scrolling even though it's inside a nested scrollview

Currently I am finishing the last details of my project and I am trying to keep a certain part inside a nested scrollview to stay on top of the screen and let only the recyclerview scroll.
This is the code I have right now:
<?xml version="1.0" encoding="utf-8"?>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="#+id/marktplaats_refresh"
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">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/imageView14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:tint="#9F000000"
app:layout_constraintCircleRadius="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/offer_bg"/>
<Button
android:id="#+id/verkoopEenProduct"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:background="#null"
android:text="Verkoop een product"
android:textColor="#color/white"
android:textSize="12sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<EditText
android:id="#+id/button5"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:background="#drawable/light_contact_buttons"
android:hint="Zoek in marktplaats"
android:textAlignment="center"
android:gravity="center_vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView33"/>
<TextView
android:id="#+id/textView32"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:text="Marktplaats"
android:textColor="#color/white"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/verkoopEenProduct"/>
<TextView
android:id="#+id/textView33"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:text="Hier vind u alles wat u nodig\nhebt voor uw praktijk"
android:textColor="#color/white"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView32"/>
<TextView
android:id="#+id/textView34"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:text="Alle producten"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView14"/>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/marktplaats_recyclerview"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView34"/>
<Button
android:id="#+id/button11"
android:translationX="-20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#null"
android:rotation="180"
android:text="➜"
android:textColor="#color/white"
android:textSize="36sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
And this is my kotlin
class MarktplaatsOverview : ApplicationFragment(){
var products: Array<MarketModel> = arrayOf()
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
super.onCreateView(inflater, container, savedInstanceState)
return inflater.inflate(R.layout.fragment_marktplaats, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
marktplaats_refresh.setOnRefreshListener {
refreshData()
marktplaats_refresh.isRefreshing = false
}
button11.setOnClickListener {
navController.navigate(R.id.action_marktplaatsOverview_to_more)
}
button5.requestFocus()
refreshData()
verkoopEenProduct.setOnClickListener {
navController.navigate(R.id.action_marktplaatsOverview_to_marktplaatsDetail)
}
}
private fun refreshData() {
if (DataStorage.market.isNotEmpty()) {
setupRecyclerView()
} else {
SharedInstance.api.getAllMarketItems {
if (isAdded) {
setupRecyclerView()
}
}
}
}
private fun setupRecyclerView(){
SharedInstance.api.getAllMarketItems {
products = DataStorage.market
val xLayoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, true)
xLayoutManager.stackFromEnd = true
marktplaats_recyclerview.layoutManager = xLayoutManager
marktplaats_recyclerview.adapter = MarktplaatsAdapter(products)
}
}
}
Does anyone have a solution for this awkward problem? I've been trying to do some restructuring of the swiperefreshlayout, scrollviews and constraints but no succes so far.
I also can't find anything on the internet where someone wants the same as me...
As per your question description, I am assuming that you face an issue that recycler view scroll or take focus automatically while you open screen and you need to stick layout at the top so pass this field on your parent layout.
android:descendantFocusability="blocksDescendants"
or replace your SwipeRefreshLayout
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="#+id/marktplaats_refresh"
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:descendantFocusability="blocksDescendants"
android:layout_height="match_parent">
I hope it helps you.

Android gridview in fragment can't scrolling

I have one page called products. When page is loaded it shows productsfragment. This fragment has one RecyclerView which doesn't have any problem. On selecting a product a new fragment opens up and shows the list of product prices fragment. This fragment has one RecyclerView and the scrolling here doesn't works.
I tried gridview and cardview but they too are not scrolling. I tried gridview in scroll view or nested scroll view, they are also not scrolling.
here is my fragment with RecyclerView which is not scrolling
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/sorderfragment_step1_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".Activities.OrderSelect.Fragments.ProductSingleOrder.SOrderFragment_Step1">
<android.support.v7.widget.RecyclerView
android:id="#+id/gvProductPrices"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
and its my RecyclerView item view
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="200dp"
android:layout_height="200dp"
android:gravity="center"
android:maxHeight="200dp"
android:minHeight="200dp"
android:background="#layout/border2"
android:padding="0dp"
android:orientation="vertical">
<TextView
android:id="#+id/txtPriceName"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:gravity="center"
android:text="Kucuk Boy Whopper"
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/constraintLayout4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.constraint.ConstraintLayout
android:id="#+id/constraintLayout4"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="0dp"
android:background="#000000"
app:layout_constraintBottom_toTopOf="#+id/txtPrice"
app:layout_constraintEnd_toEndOf="parent">
</android.support.constraint.ConstraintLayout>
<TextView
android:id="#+id/txtPrice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:gravity="center"
android:text="14.99"
android:textColor="#000000"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</LinearLayout>
and my adapter
class PriceAdapter(val priceList : List<ProductPrice>,
val context: Context) : RecyclerView.Adapter<ViewHolder>() {
override fun onCreateViewHolder(p0: ViewGroup, p1: Int): ViewHolder {
return ViewHolder(LayoutInflater.from(context).inflate(R.layout.gv_product_prices, p0, false))
}
override fun getItemCount(): Int {
return priceList.size
}
override fun onBindViewHolder(p0: ViewHolder, p1: Int) {
val price = priceList[p1]
p0.txtPriceName.text = price.getDescription()
p0.txtPriceName.isAllCaps = true
p0.txtPrice.text = BaseHelper.getNumericStr(price.getPrice())
}
}
class ViewHolder (view: View) : RecyclerView.ViewHolder(view) {
val txtPriceName = view.txtPriceName!!
val txtPrice = view.txtPrice!!
}
and my fragment code
class SOrderFragment_Step1 : Fragment() {
private var _priceRepository = ProductPriceRepository(OrderRepository.orderSelect!!)
private var priceAdapter: PriceAdapter? = null
private var prices: List<ProductPrice>? = null
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_sorder_step1, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
configurePrices()
}
private fun configurePrices() {
prices = _priceRepository.getPriceByProductId(OrderRepository.currentProduct!!.getId())
gvProductPrices.layoutManager = GridLayoutManager(OrderRepository.orderSelect!!, 2)
gvProductPrices.adapter = PriceAdapter(prices!!, this, OrderRepository.orderSelect!!)
}
fun priceSelect(price: ProductPrice) {
Toast.makeText(OrderRepository.orderSelect!!, price.getDescription(), Toast.LENGTH_LONG).show()
}
}
and also fragment change like this
val manager = this.fragmentManager!!.beginTransaction()
manager.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out)
manager.replace(R.id.fragmentProductSteps, SOrderFragment_Step1(), "detailFragment").commit()
and fragment base activity 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"
android:id="#+id/order_select_layout"
tools:context=".OrderSelect">
<GridView
android:id="#+id/gvProductGroups"
android:layout_width="165dp"
android:layout_height="0dp"
android:layout_marginTop="16dp"
android:scrollbars="none"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linearLayout" />
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="0dp"
android:layout_height="225dp"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.constraint.ConstraintLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="7">
<include
layout="#layout/activity_advertise_partition"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/orderProductLayout"
android:layout_width="0dp"
android:layout_height="83dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:background="#layout/gv_order_products_border"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/btnCancelCurrentOrder2"
app:layout_constraintStart_toEndOf="#+id/gvProductGroups">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:layout_marginTop="5dp"
android:id="#+id/paymentView"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
android:layout_weight="1">
<TextView
android:id="#+id/txtTotalL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TOPLAM :"
android:textColor="#bc3030"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/txtPriceL"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="-1dp"
android:layout_weight="1"
android:gravity="left|center"
android:text="₺ 0.00"
android:textColor="#000000"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/imgOrderButton"
app:layout_constraintStart_toEndOf="#+id/txtTotalL"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<Button
android:id="#+id/imgOrderButton"
android:layout_width="175dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:background="#15912e"
android:padding="15sp"
android:text="Sepeti Goster"
android:textColor="#FFFFFF"
android:textSize="18sp"
android:textStyle="bold"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</LinearLayout>
<fragment
android:id="#+id/fragmentProductSteps"
android:name="com.example.alknakralar.kios.Helpers.BlankFragment"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="24dp"
android:layout_marginLeft="24dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="24dp"
android:layout_marginRight="24dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toTopOf="#+id/orderProductLayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/gvProductGroups"
app:layout_constraintTop_toBottomOf="#+id/linearLayout" />
<Button
android:id="#+id/btnCancelCurrentOrder2"
android:layout_width="125dp"
android:layout_height="0dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:background="#ff0000"
android:text="SEPETI BOSALT"
android:textColor="#FFFFFF"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/imgBackFromProducts"
app:layout_constraintTop_toBottomOf="#+id/fragmentProductSteps" />
<ImageView
android:id="#+id/imgBackFromProducts"
android:layout_width="70dp"
android:layout_height="0dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/fragmentProductSteps"
app:srcCompat="#drawable/back" />
</android.support.constraint.ConstraintLayout>
How can i fix this issue ?
Sugession: Why are you using grid view and setting adapter to it where you have another approach and commonly used approach.
Which is to use recycler view and set its layout manager as GridLayout manager
Below single line will make your job done
recyclerView.setLayoutManager(new GridLayoutManager(this, numberOfColumns));

Categories

Resources