-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
creat viewholder and adapter for group
- Loading branch information
Showing
7 changed files
with
92 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
app/src/main/java/com/developer/kulloveth/expandablelistsamplewithroom/data/MainViewHoder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.developer.kulloveth.expandablelistsamplewithroom.data | ||
|
||
import android.view.View | ||
import android.widget.TextView | ||
import com.developer.kulloveth.expandablelistsamplewithroom.R | ||
import com.developer.kulloveth.expandablelistsamplewithroom.data.model.Continents | ||
import com.developer.kulloveth.expandablelistsamplewithroom.data.model.Countrys | ||
import com.thoughtbot.expandablerecyclerview.viewholders.ChildViewHolder | ||
import com.thoughtbot.expandablerecyclerview.viewholders.GroupViewHolder | ||
|
||
|
||
class CountryViewHolder(itemView: View) : ChildViewHolder(itemView) { | ||
val countryName = itemView.findViewById<TextView>(R.id.countryName) | ||
|
||
fun bind(countrys: Countrys) { | ||
countryName.text = countrys.countryName | ||
} | ||
} | ||
|
||
class ContinentViewHolder(itemView: View) : GroupViewHolder(itemView) { | ||
val continentName = itemView.findViewById<TextView>(R.id.continent) | ||
|
||
fun bind(continent: Continents) { | ||
continentName.text = continent.ContinentName | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...ain/java/com/developer/kulloveth/expandablelistsamplewithroom/data/ui/ContinentAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.developer.kulloveth.expandablelistsamplewithroom.data.ui | ||
|
||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import android.widget.ExpandableListAdapter | ||
import com.developer.kulloveth.expandablelistsamplewithroom.R | ||
import com.developer.kulloveth.expandablelistsamplewithroom.data.ContinentViewHolder | ||
import com.developer.kulloveth.expandablelistsamplewithroom.data.CountryViewHolder | ||
import com.developer.kulloveth.expandablelistsamplewithroom.data.model.Continents | ||
import com.developer.kulloveth.expandablelistsamplewithroom.data.model.Countrys | ||
import com.thoughtbot.expandablerecyclerview.ExpandableRecyclerViewAdapter | ||
import com.thoughtbot.expandablerecyclerview.models.ExpandableGroup | ||
|
||
class ContinentAdapter(groups: List<ExpandableGroup<*>>?) : | ||
ExpandableRecyclerViewAdapter<ContinentViewHolder, CountryViewHolder>( | ||
groups | ||
) { | ||
|
||
|
||
override fun onCreateGroupViewHolder(parent: ViewGroup?, viewType: Int): ContinentViewHolder { | ||
val itemView = | ||
LayoutInflater.from(parent?.context).inflate(R.layout.continent_layout, parent, false) | ||
return ContinentViewHolder(itemView) | ||
} | ||
|
||
override fun onCreateChildViewHolder(parent: ViewGroup?, viewType: Int): CountryViewHolder { | ||
val itemView = | ||
LayoutInflater.from(parent?.context).inflate(R.layout.countrys_layout, parent, false) | ||
return CountryViewHolder(itemView) | ||
} | ||
|
||
override fun onBindChildViewHolder( | ||
holder: CountryViewHolder?, | ||
flatPosition: Int, | ||
group: ExpandableGroup<*>?, | ||
childIndex: Int | ||
) { | ||
val countrys: Countrys = group?.items?.get(childIndex) as Countrys | ||
holder?.bind(countrys) | ||
} | ||
|
||
override fun onBindGroupViewHolder( | ||
holder: ContinentViewHolder?, | ||
flatPosition: Int, | ||
group: ExpandableGroup<*>? | ||
) { | ||
val continents: Continents = group as Continents | ||
holder?.bind(continents) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters