Skip to content

Commit 7d8bb13

Browse files
committed
show expandablelist view
1 parent b2ca71a commit 7d8bb13

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

app/proguard-rules.pro

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
# class:
1515
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
1616
# public *;
17-
#}
17+
#}

imitate/src/main/java/com/engineer/imitate/ui/activity/MyExpandableListViewActivity.kt

+18-10
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import android.view.View
77
import android.view.ViewGroup
88
import android.widget.BaseExpandableListAdapter
99
import android.widget.ExpandableListView.OnGroupCollapseListener
10-
import android.widget.ExpandableListView.OnGroupExpandListener
1110
import android.widget.TextView
1211
import androidx.appcompat.app.AppCompatActivity
1312
import com.engineer.imitate.R
@@ -32,12 +31,12 @@ class MyExpandableListViewActivity : AppCompatActivity() {
3231
//给ExpandableListAdapter设置适配器---自定义适配器需要继承BaseExpandableListAdapter()实现其中的方法
3332
val myExpandableListAdapter = MyExpandableListAdapter()
3433

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))
3736
//设置适配器
3837
expandable_lv.setAdapter(myExpandableListAdapter)
3938
//去掉group默认的箭头
40-
expandable_lv.setGroupIndicator(null)
39+
// expandable_lv.setGroupIndicator(null)
4140
//设置组可拉伸的监听器,拉伸时会调用其中的onGroupExpand()方法
4241
expandable_lv.setOnGroupExpandListener {
4342
/**
@@ -46,10 +45,10 @@ class MyExpandableListViewActivity : AppCompatActivity() {
4645
/**
4746
* 实现打开只能打开一个组的功能,打开一个组,已将打开的组会自动收缩
4847
*/
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
5352
}
5453
//设置组收缩的监听器,收缩时会调用其中的onGroupCollapse()方法
5554
expandable_lv.setOnGroupCollapseListener(OnGroupCollapseListener { })
@@ -111,8 +110,9 @@ class MyExpandableListViewActivity : AppCompatActivity() {
111110
*/
112111
override fun getGroupView(groupPosition: Int, isExpanded: Boolean,
113112
convertView: View?, parent: ViewGroup): View? {
113+
114114
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)
116116
val group_text = view.findViewById(R.id.group_text) as TextView
117117
group_text.text = groupData[groupPosition]
118118
return view
@@ -124,7 +124,7 @@ class MyExpandableListViewActivity : AppCompatActivity() {
124124
override fun getChildView(groupPosition: Int, childPosition: Int,
125125
isLastChild: Boolean, convertView: View?, parent: ViewGroup): View? {
126126
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)
128128
val child_text = view.findViewById(R.id.child_text) as TextView
129129
child_text.text = childData[groupPosition][childPosition]
130130
return view
@@ -134,6 +134,14 @@ class MyExpandableListViewActivity : AppCompatActivity() {
134134
return false
135135
}
136136

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+
137145
}
138146

139147
}

imitate/src/main/res/layout/expandable_group_item.xml

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:tools="http://schemas.android.com/tools"
44
android:layout_width="match_parent"
5-
android:layout_height="match_parent"
5+
android:layout_height="wrap_content"
66
android:orientation="vertical">
77

88
<TextView
99
android:id="@+id/group_text"
1010
android:layout_width="match_parent"
1111
android:layout_height="wrap_content"
12-
android:padding="8dp"
1312
android:textColor="@color/black"
1413
android:textSize="16sp"
14+
android:paddingTop="8dp"
15+
android:paddingBottom="8dp"
16+
android:paddingStart="32dp"
17+
android:paddingEnd="32dp"
1518
android:textStyle="bold"
1619
tools:text="111" />
1720

0 commit comments

Comments
 (0)