I
Size: a a a
I
I
I
A
A
I
A
class DataPump {
fun getData(): HashMap<String, MutableList<String>> {
val expandableListDetail: HashMap<String, MutableList<String>> = hashMapOf()
val football: MutableList<String> = arrayListOf()
football.add("Russia")
football.add("USA")
football.add("Kazakhstan")
val basketball: MutableList<String> = arrayListOf()
basketball.add("Russia")
basketball.add("USA")
basketball.add("Kazakhstan")
val tennis: MutableList<String> = arrayListOf()
tennis.add("Russia")
tennis.add("USA")
tennis.add("Kazakhstan")
expandableListDetail.put("FOOTBALL", football)
expandableListDetail.put("BASKETBALL", basketball)
expandableListDetail.put("TENNIS", tennis)
return expandableListDetail
}
fun getTitles(): MutableList<String>{
val expandableListTitles: MutableList<String> = arrayListOf()
expandableListTitles.add("Football")
expandableListTitles.add("Basketball")
expandableListTitles.add("Tennis")
return expandableListTitles
}
}
A
class MainActivity : AppCompatActivity() {
lateinit var expandableListView: ExpandableListView
lateinit var expandableAdapter: CustomExpandableAdapter
lateinit var expandableListDetail: HashMap<String, MutableList<String>>
lateinit var expandableListTitle: MutableList<String>
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
expandableListView = findViewById(R.id.expandablelistview)
expandableListDetail = DataPump().getData()
expandableListTitle = DataPump().getTitles()
expandableAdapter = CustomExpandableAdapter(this, expandableListDetail, expandableListTitle)
expandableListView.setAdapter(expandableAdapter)
}
}
A
class CustomExpandableAdapter(val context: Context, val expandableListDetail: HashMap<String, MutableList<String>>, val expandableListTitle: MutableList<String>): BaseExpandableListAdapter() {
override fun getGroupCount(): Int {
return expandableListTitle.size
}
override fun getChildrenCount(groupPosition: Int): Int {
return expandableListDetail.size
}
override fun getGroup(groupPosition: Int): Any {
return expandableListTitle[groupPosition]
}
override fun getChild(groupPosition: Int, childPosition: Int): String? {
return expandableListDetail.get(groupPosition)?.get(childPosition)
}
override fun getGroupId(groupPosition: Int): Long {
return groupPosition.toLong()
}
override fun getChildId(groupPosition: Int, childPosition: Int): Long {
return childPosition.toLong()
}
override fun hasStableIds(): Boolean {
return false
}
override fun getGroupView(
groupPosition: Int,
isExpanded: Boolean,
convertView: View?,
parent: ViewGroup?
): View? {
val listTitle: String = getGroup(groupPosition) as String
var mConvertView = convertView
if (mConvertView == null){
val layoutInflater: LayoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
mConvertView = layoutInflater.inflate(R.layout.group_row, null)
}
val listTitleTextView: TextView? = mConvertView?.findViewById(R.id.group_tv)
listTitleTextView?.typeface = Typeface.DEFAULT_BOLD
listTitleTextView?.text = listTitle
return mConvertView
}
override fun getChildView(
groupPosition: Int,
childPosition: Int,
isLastChild: Boolean,
convertView: View?,
parent: ViewGroup?
): View? {
val expandedListText = getChild(groupPosition, childPosition)
var mConvertView = convertView
if (mConvertView == null){
val layoutInflater: LayoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
mConvertView = layoutInflater.inflate(R.layout.item_row, null)
}
val expandedListTextView: TextView? = mConvertView?.findViewById(R.id.item_tv)
expandedListTextView?.text = expandedListText
return mConvertView
}
override fun isChildSelectable(groupPosition: Int, childPosition: Int): Boolean {
return true
}
}
ДР
class DataPump {
fun getData(): HashMap<String, MutableList<String>> {
val expandableListDetail: HashMap<String, MutableList<String>> = hashMapOf()
val football: MutableList<String> = arrayListOf()
football.add("Russia")
football.add("USA")
football.add("Kazakhstan")
val basketball: MutableList<String> = arrayListOf()
basketball.add("Russia")
basketball.add("USA")
basketball.add("Kazakhstan")
val tennis: MutableList<String> = arrayListOf()
tennis.add("Russia")
tennis.add("USA")
tennis.add("Kazakhstan")
expandableListDetail.put("FOOTBALL", football)
expandableListDetail.put("BASKETBALL", basketball)
expandableListDetail.put("TENNIS", tennis)
return expandableListDetail
}
fun getTitles(): MutableList<String>{
val expandableListTitles: MutableList<String> = arrayListOf()
expandableListTitles.add("Football")
expandableListTitles.add("Basketball")
expandableListTitles.add("Tennis")
return expandableListTitles
}
}
I
class CustomExpandableAdapter(val context: Context, val expandableListDetail: HashMap<String, MutableList<String>>, val expandableListTitle: MutableList<String>): BaseExpandableListAdapter() {
override fun getGroupCount(): Int {
return expandableListTitle.size
}
override fun getChildrenCount(groupPosition: Int): Int {
return expandableListDetail.size
}
override fun getGroup(groupPosition: Int): Any {
return expandableListTitle[groupPosition]
}
override fun getChild(groupPosition: Int, childPosition: Int): String? {
return expandableListDetail.get(groupPosition)?.get(childPosition)
}
override fun getGroupId(groupPosition: Int): Long {
return groupPosition.toLong()
}
override fun getChildId(groupPosition: Int, childPosition: Int): Long {
return childPosition.toLong()
}
override fun hasStableIds(): Boolean {
return false
}
override fun getGroupView(
groupPosition: Int,
isExpanded: Boolean,
convertView: View?,
parent: ViewGroup?
): View? {
val listTitle: String = getGroup(groupPosition) as String
var mConvertView = convertView
if (mConvertView == null){
val layoutInflater: LayoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
mConvertView = layoutInflater.inflate(R.layout.group_row, null)
}
val listTitleTextView: TextView? = mConvertView?.findViewById(R.id.group_tv)
listTitleTextView?.typeface = Typeface.DEFAULT_BOLD
listTitleTextView?.text = listTitle
return mConvertView
}
override fun getChildView(
groupPosition: Int,
childPosition: Int,
isLastChild: Boolean,
convertView: View?,
parent: ViewGroup?
): View? {
val expandedListText = getChild(groupPosition, childPosition)
var mConvertView = convertView
if (mConvertView == null){
val layoutInflater: LayoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
mConvertView = layoutInflater.inflate(R.layout.item_row, null)
}
val expandedListTextView: TextView? = mConvertView?.findViewById(R.id.item_tv)
expandedListTextView?.text = expandedListText
return mConvertView
}
override fun isChildSelectable(groupPosition: Int, childPosition: Int): Boolean {
return true
}
}
I
class CustomExpandableAdapter(val context: Context, val expandableListDetail: HashMap<String, MutableList<String>>, val expandableListTitle: MutableList<String>): BaseExpandableListAdapter() {
override fun getGroupCount(): Int {
return expandableListTitle.size
}
override fun getChildrenCount(groupPosition: Int): Int {
return expandableListDetail.size
}
override fun getGroup(groupPosition: Int): Any {
return expandableListTitle[groupPosition]
}
override fun getChild(groupPosition: Int, childPosition: Int): String? {
return expandableListDetail.get(groupPosition)?.get(childPosition)
}
override fun getGroupId(groupPosition: Int): Long {
return groupPosition.toLong()
}
override fun getChildId(groupPosition: Int, childPosition: Int): Long {
return childPosition.toLong()
}
override fun hasStableIds(): Boolean {
return false
}
override fun getGroupView(
groupPosition: Int,
isExpanded: Boolean,
convertView: View?,
parent: ViewGroup?
): View? {
val listTitle: String = getGroup(groupPosition) as String
var mConvertView = convertView
if (mConvertView == null){
val layoutInflater: LayoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
mConvertView = layoutInflater.inflate(R.layout.group_row, null)
}
val listTitleTextView: TextView? = mConvertView?.findViewById(R.id.group_tv)
listTitleTextView?.typeface = Typeface.DEFAULT_BOLD
listTitleTextView?.text = listTitle
return mConvertView
}
override fun getChildView(
groupPosition: Int,
childPosition: Int,
isLastChild: Boolean,
convertView: View?,
parent: ViewGroup?
): View? {
val expandedListText = getChild(groupPosition, childPosition)
var mConvertView = convertView
if (mConvertView == null){
val layoutInflater: LayoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
mConvertView = layoutInflater.inflate(R.layout.item_row, null)
}
val expandedListTextView: TextView? = mConvertView?.findViewById(R.id.item_tv)
expandedListTextView?.text = expandedListText
return mConvertView
}
override fun isChildSelectable(groupPosition: Int, childPosition: Int): Boolean {
return true
}
}
A
A
I
A
I
A
I
I