my group has 5 items, but it repeat them the same and become 10, i dont know why. below is my adapter and till now any solution for fill_parent or match_parent nothing is working for me.
class FilterAdapter(private val context: Context, private val teamName: ArrayList) : BaseExpandableListAdapter() {
override fun getChild(groupPosition: Int, childPosition: Int): Any {
val productList = teamName[groupPosition].playerName
return productList[childPosition]
}
override fun getChildId(groupPosition: Int, childPosition: Int): Long {
return childPosition.toLong()
}
override fun getChildView(
groupPosition: Int, childPosition: Int, isLastChild: Boolean,
view: View?, parent: ViewGroup
): View {
var view = view
val detailInfo = getChild(groupPosition, childPosition) as ChildData
if (view == null) {
val infalInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
view = infalInflater.inflate(R.layout.item_layout_filter_child, null)
}
val childItem = view!!.findViewById<View>(R.id.childDetailItem) as TextView
val linChildLayout = view.findViewById<View>(R.id.linFilterChild) as LinearLayout
val filterCheckBox = view.findViewById<View>(R.id.filterCheckBox) as CheckBox
val linCheckbox = view.findViewById<View>(R.id.linCheckbox) as LinearLayout
childItem.text = detailInfo.name.trim { it <= ' ' }
Log.e("item", "" + childItem.text)
linChildLayout.setOnClickListener {
// Log.e("filterchildPosition"," "+detailInfo.getName()+" status is now "+filterCheckBox.isChecked());
if (filterCheckBox.isChecked) {
filterCheckBox.isChecked = false
Log.e("filterchildPositionif", " " + detailInfo.name + " status is now " + filterCheckBox.isChecked)
} else {
filterCheckBox.isChecked = true
Log.e(
"filterchildPositionelse",
" " + detailInfo.name + " status is now " + filterCheckBox.isChecked
)
}
}
filterCheckBox.setOnCheckedChangeListener { buttonView, isChecked ->
if (filterCheckBox.isChecked) {
// your code to checked checkbox
Log.e("filterchildPositionif", " " + detailInfo.name + " status is now " + filterCheckBox.isChecked)
} else {
// your code to no checked checkbox
Log.e(
"filterchildPositionelse",
" " + detailInfo.name + " status is now " + filterCheckBox.isChecked
)
}
}
return view
}
override fun getChildrenCount(groupPosition: Int): Int {
val productList = teamName[groupPosition].playerName
Log.e("listsize",productList.size.toString())
return productList.size
}
override fun getGroup(groupPosition: Int): Any {
return teamName[groupPosition]
}
override fun getGroupCount(): Int {
return teamName.size
}
override fun getGroupId(groupPosition: Int): Long {
return groupPosition.toLong()
}
override fun getGroupView(
groupPosition: Int, isLastChild: Boolean, view: View?,
parent: ViewGroup
): View {
var view = view
val headerInfo = getGroup(groupPosition) as GroupData
if (view == null) {
val inf = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
view = inf.inflate(R.layout.item_layout_filter_group, null)
}
val heading = view!!.findViewById<View>(R.id.heading) as TextView
heading.text = headerInfo.name.trim { it <= ' ' }
return view
}
override fun hasStableIds(): Boolean {
return true
}
override fun isChildSelectable(groupPosition: Int, childPosition: Int): Boolean {
return true
}
}
what i did is i just decreased the count of getChildrenCount to half it was first half that was repeating.
override fun getChildrenCount(groupPosition: Int): Int {
}