Kotlin组中的ExpandableListView多级第一个子项的位置始终为0

Kotlin组中的ExpandableListView多级第一个子项的位置始终为0,kotlin,expandablelistview,multi-level,Kotlin,Expandablelistview,Multi Level,我是科特林的新手,现在正在学习这种编码语言。 目前,我遇到了一个问题,即在我的多级可扩展列表视图的第二级中,groupPosition始终为“0”。 视图始终显示3次相同的对象,但必须是3个不同的对象 数据来自本地运行的SQLLite数据库,Databasequery工作正常 这是我的代码,希望你能帮我 类pflegeRabGru:AppCompatActivity(){ val ctx:Context=this 内部变量expandableListView:expandableListView

我是科特林的新手,现在正在学习这种编码语言。 目前,我遇到了一个问题,即在我的多级可扩展列表视图的第二级中,groupPosition始终为“0”。 视图始终显示3次相同的对象,但必须是3个不同的对象

数据来自本地运行的SQLLite数据库,Databasequery工作正常

这是我的代码,希望你能帮我

类pflegeRabGru:AppCompatActivity(){
val ctx:Context=this
内部变量expandableListView:expandableListView?=null
内部变量listAdapter:ExpandableListAdapter?=null
重写创建时的乐趣(savedInstanceState:Bundle?){
super.onCreate(savedInstanceState)
setContentView(R.layout.activity\u pflege\u rabgru)
expandableListView=findViewById(R.id.expRabListView)
if(expandableListView!=null){
listAdapter=adapter\u RabGruKat(此)
expandableListView!!.setAdapter(listAdapter)
}
}
第一个适配器 适配器_RabGruKat

类适配器\u RabGruKat内部构造函数(private val context:context):BaseExpandableListAdapter(){
val lclDb=lclDBHelper(上下文)
val listRabgru=ArrayList()
val listRabFields=ArrayList()
val listCats=ArrayList()
val listReadedRabgru=getRabForGroups()
val listReadedRabKats=getKatsForGroups()
覆盖fun getChild(groupPosition:Int,childPosition:Int):Int{
返回子位置
}
覆盖有趣的getChildId(groupPosition:Int,childPosition:Int):长{
return childPosition.toLong()
}
覆盖趣味getChildView(groupPosition:Int,childPosition:Int,isLastChild:Boolean,convertView:View?,父对象:ViewGroup):视图{
var convertView=convertView
var subObjects=ExpandableListView(上下文)
子对象!!.setAdapter(适配器\u RabGruKatChilds(上下文,childPosition.toLong(),getGroup(groupPosition.get(groupPosition.WAHID))
子对象!!.setGroupIndicator(空)
返回子对象
}
覆盖趣味getChildrenCount(groupPosition:Int):Int{
返回列表大小
}
重写fun getGroup(groupPosition:Int):ArrayList{
返回列表
}
重写getGroupCount():Int{
返回listRabgru.size
}
覆盖有趣的getGroupId(groupPosition:Int):长{
returngroupposition.toLong()
}
覆盖有趣的getGroupView(groupPosition:Int,isExpanded:Boolean,convertView:View?,父级:ViewGroup):视图{
var convertView=convertView
val groupTitle=getGroup(groupPosition).get(groupPosition).WAH_RABGRU+“”+getGroup(groupPosition).get(groupPosition).WAH_RABGRUTEXT
val groupId=getGroup(groupPosition).get(groupPosition).WAHID
if(convertView==null){
val layoutInflater=this.context.getSystemService(context.LAYOUT\u INFLATER\u SERVICE)作为layoutInflater
convertView=LayoutFlater.充气(R.layout.parent\u pflege\u rabgru,null)
}
val listRabGruTitle=convertView!!.findViewById(R.id.txtRabgruName)
val listRabId=convertView!!.findviewbyd(R.id.txtRabGruId)
listRabGruTitle.text=groupTitle
listRabId.text=groupId.toString()
返回转换视图
}
重写表ID():布尔值{
返回真值
}
重写fun isChildSelectable(groupPosition:Int,childPosition:Int):布尔值{
返回真值
}
趣味getRabForGroups():ArrayList{
lclDb.readAllArtRabGru().forEach(){
添加(ArtRabGru(it.WAHID,it.WAH_-RABGRU,it.WAH_-RABGRU-text))
}
返回列表
}
趣味getKatsForGroups():ArrayList{
lclDb.readAllCategory().forEach{
添加(类别(it.KATID、it.KATNAME))
}
返回列表猫
}
}
第二级适配器


类适配器\u RabGruKatChilds内部构造函数(private val context:context,private val childPositionOtherAdapter:Long,private val selectedRabgru:Long):BaseExpandableListAdapter(){
val lclDb=lclDBHelper(上下文)
var listCats=ArrayList()
val readCats=getKatsForGroups()
val rabbields=ArrayList()
val readrabbields=getFieldRabs()
重写fun getChild(childPosition:Int,groupPosition:Int):字段{
返回rabbields.get(childPosition)
}
覆盖有趣的getChildId(groupPosition:Int,childPosition:Int):长{
return childPosition.toLong()
}
覆盖趣味getChildView(groupPosition:Int,childPosition:Int,isLastChild:Boolean,convertView:View?,父对象:ViewGroup):视图{
var convertView=convertView
val fieldId=getChild(childPosition,groupPosition).RABFIELDID
val fieldName=getChild(childPosition,groupPosition).RABFIELDTEXT
if(convertView==null){
val layoutInflater=this.context.getSystemService(context.LAYOUT\u INFLATER\u SERVICE)作为layoutInflater
convertView=LayoutFlater.inflate(R.layout.pflegefieldsitems,null)
}
val txtfieldId=convertView!!.findviewbyd(R.id.txtfieldId)
val txtfieldName=convertView!!.findviewbyd(R.id.txtfieldName)
txtfieldId.text=fieldId.toString()
txtfieldName.text=fieldName
返回转换视图
}
覆盖趣味getChildrenCount(groupPosition:Int):Int{
返回rabbields.size
}
覆盖fun getGroup(groupPosition:Int):类别{
Log.i(“INFO”,“getGroupt中的GroupPosition=“+GroupPosition.toString())
返回listCats.get(groupPosition)
}
重写getGroupCount():Int{
返回列表大小
}
覆盖有趣的getGroupId(groupPosition:Int):长{
returngroupposition.toLong()
}
覆盖有趣的getGroupView(groupPosition:Int,isExpanded:Boolean,convertView:View?,父级:ViewGroup):View{
无功变换器