@@ -7,7 +7,6 @@ import android.view.View
7
7
import android.view.ViewGroup
8
8
import android.widget.BaseExpandableListAdapter
9
9
import android.widget.ExpandableListView.OnGroupCollapseListener
10
- import android.widget.ExpandableListView.OnGroupExpandListener
11
10
import android.widget.TextView
12
11
import androidx.appcompat.app.AppCompatActivity
13
12
import com.engineer.imitate.R
@@ -32,12 +31,12 @@ class MyExpandableListViewActivity : AppCompatActivity() {
32
31
// 给ExpandableListAdapter设置适配器---自定义适配器需要继承BaseExpandableListAdapter()实现其中的方法
33
32
val myExpandableListAdapter = MyExpandableListAdapter ()
34
33
35
- expandable_lv.setIndicatorBounds(10 , 10 )
36
- expandable_lv.setChildDivider(getDrawable(R .drawable.line))
34
+ // expandable_lv.setIndicatorBounds(10, 10)
35
+ // expandable_lv.setChildDivider(getDrawable(R.drawable.line))
37
36
// 设置适配器
38
37
expandable_lv.setAdapter(myExpandableListAdapter)
39
38
// 去掉group默认的箭头
40
- expandable_lv.setGroupIndicator(null )
39
+ // expandable_lv.setGroupIndicator(null)
41
40
// 设置组可拉伸的监听器,拉伸时会调用其中的onGroupExpand()方法
42
41
expandable_lv.setOnGroupExpandListener {
43
42
/* *
@@ -46,10 +45,10 @@ class MyExpandableListViewActivity : AppCompatActivity() {
46
45
/* *
47
46
* 实现打开只能打开一个组的功能,打开一个组,已将打开的组会自动收缩
48
47
*/
49
- if (it != = lastGroupPosition) {
50
- expandable_lv.collapseGroup(lastGroupPosition)
51
- }
52
- lastGroupPosition = it
48
+ // if (it !== lastGroupPosition) {
49
+ // expandable_lv.collapseGroup(lastGroupPosition)
50
+ // }
51
+ // lastGroupPosition = it
53
52
}
54
53
// 设置组收缩的监听器,收缩时会调用其中的onGroupCollapse()方法
55
54
expandable_lv.setOnGroupCollapseListener(OnGroupCollapseListener { })
@@ -111,8 +110,9 @@ class MyExpandableListViewActivity : AppCompatActivity() {
111
110
*/
112
111
override fun getGroupView (groupPosition : Int , isExpanded : Boolean ,
113
112
convertView : View ? , parent : ViewGroup ): View ? {
113
+
114
114
val inflater = LayoutInflater .from(mContext)
115
- val view = inflater.inflate(R .layout.expandable_group_item, null )
115
+ val view = inflater.inflate(R .layout.expandable_group_item, parent, false )
116
116
val group_text = view.findViewById(R .id.group_text) as TextView
117
117
group_text.text = groupData[groupPosition]
118
118
return view
@@ -124,7 +124,7 @@ class MyExpandableListViewActivity : AppCompatActivity() {
124
124
override fun getChildView (groupPosition : Int , childPosition : Int ,
125
125
isLastChild : Boolean , convertView : View ? , parent : ViewGroup ): View ? {
126
126
val inflater = LayoutInflater .from(mContext)
127
- val view = inflater.inflate(R .layout.expandable_childe_item, null )
127
+ val view = inflater.inflate(R .layout.expandable_childe_item, parent, false )
128
128
val child_text = view.findViewById(R .id.child_text) as TextView
129
129
child_text.text = childData[groupPosition][childPosition]
130
130
return view
@@ -134,6 +134,14 @@ class MyExpandableListViewActivity : AppCompatActivity() {
134
134
return false
135
135
}
136
136
137
+ inner class GroupViewHolder {
138
+ private lateinit var group_text: TextView
139
+ }
140
+
141
+ inner class ChildViewHolder {
142
+ private lateinit var child_text: TextView
143
+ }
144
+
137
145
}
138
146
139
147
}
0 commit comments