From 14c319043ec775d62b4453b1b8b930d06295dda1 Mon Sep 17 00:00:00 2001 From: Pratyush Singh Date: Mon, 8 Jan 2024 18:40:59 +0530 Subject: [PATCH] fix #1440: app crash when selecting FAQ --- .../mifospay/faq/FAQListAdapter.kt | 47 +++++++++++++------ 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/faq/FAQListAdapter.kt b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/faq/FAQListAdapter.kt index b6ef51815..c615dec76 100644 --- a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/faq/FAQListAdapter.kt +++ b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/faq/FAQListAdapter.kt @@ -2,6 +2,7 @@ package org.mifos.mobilewallet.mifospay.faq import android.content.Context import android.graphics.Typeface +import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.BaseExpandableListAdapter @@ -16,12 +17,17 @@ import org.mifos.mobilewallet.mifospay.R */ class FAQListAdapter( private val context: Context, // group titles - private val listDataGroup: List, + private var listDataGroup: List, // child data - private val listDataChild: HashMap> + private var listDataChild: HashMap> ) : BaseExpandableListAdapter() { + init { + listDataChild = listDataChild + } + override fun getChild(groupPosition: Int, childPosititon: Int): Any { - return listDataChild[listDataGroup[groupPosition]]?.get(childPosititon) ?: 0 + return listDataChild[listDataGroup[groupPosition]] + ?.get(childPosititon)!! } override fun getChildId(groupPosition: Int, childPosition: Int): Long { @@ -30,18 +36,24 @@ class FAQListAdapter( override fun getChildView( groupPosition: Int, childPosition: Int, - isLastChild: Boolean, convertView: View, parent: ViewGroup - ): View { - val convertView = convertView + isLastChild: Boolean, convertView: View?, parent: ViewGroup + ): View? { + var convertView = convertView val childText = getChild(groupPosition, childPosition) as String + if (convertView == null) { + val layoutInflater = context + .getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater + convertView = layoutInflater.inflate(R.layout.faq_list_child, parent,false) + } val textViewChild = convertView - .findViewById(R.id.faq_list_child) - textViewChild.text = childText + ?.findViewById(R.id.faq_list_child) + textViewChild?.text = childText return convertView } override fun getChildrenCount(groupPosition: Int): Int { - return listDataChild[listDataGroup[groupPosition]]?.size ?: 0 + return listDataChild[listDataGroup[groupPosition]] + ?.size!! } override fun getGroup(groupPosition: Int): Any { @@ -58,14 +70,19 @@ class FAQListAdapter( override fun getGroupView( groupPosition: Int, isExpanded: Boolean, - convertView: View, parent: ViewGroup - ): View { - val convertView = convertView + convertView: View?, parent: ViewGroup + ): View? { + var convertView = convertView val headerTitle = getGroup(groupPosition) as String + if (convertView == null) { + val layoutInflater = context + .getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater + convertView = layoutInflater.inflate(R.layout.faq_list_group, parent,false) + } val textViewGroup = convertView - .findViewById(R.id.faq_list_group) - textViewGroup.setTypeface(null, Typeface.BOLD) - textViewGroup.text = headerTitle + ?.findViewById(R.id.faq_list_group) + textViewGroup?.setTypeface(null, Typeface.BOLD) + textViewGroup?.text = headerTitle return convertView }