在我的Kotlin项目中,从主要活动来看,从底层菜单中添加了一个碎片(人群碎片)。 在这种碎块中,通过喷洒回收器观看了图像和名称。 如果要点击胎面图,就会打开另一块碎片(ProfileviewPeople),然后,如果背纽扣式电话和roid子电话,则会发生主要活动。 我需要从情况简介会人那里回头,用几页人。 我添加了儿童A. 导 言dapter代码,从儿童A. 导 言dapteri 点击了情况简介会的分裂。 i HA. 导 言VE A. 导 言DDED PEOPLENEA. 导 言RBY FRA. 导 言 PA. 导 言SSING A. 导 言RRA. 导 言YLIST CODE,PA. 导 言RENT A. 导 言DA. 导 言PTER and CHILD A. 导 言DA. 导 言PTER CODES
private fun loadA. 导 言ndDisplayProfile(uid: Int, cntxt: Context) {
val bundle = Bundle()
bundle.putInt("userId", uid)
val fragment = ProfileViewPeople.newInstance(uid).apply {
arguments = bundle
}
val appCompatA. 导 言ctivity = cntx as A. 导 言ppCompatA. 导 言ctivity
appCompatA. 导 言ctivity.supportFragmentManager.beginTransaction()
.setCustomA. 导 言nimations( R.anim.slide_in_right,
R.anim.slide_out_left, R.anim.slide_in_left, R.anim.slide_out_right )
.add(R.id.peopleNearBy, fragment).addToBackStack("selectx")
.commit()
Log.d("ChildA. 导 言dapter", " backStackEntryCount "+appCompatA. 导 言ctivity.supportFragmentManager.backStackEntryCount)
}
FUL CODE:
class ChildA. 导 言dapter(private val
myChildList:MutableList<Peoples>):RecyclerView.A. 导 言dapter<ChildA. 导 言dapter.ChildHolder>() {
class ChildHolder(itemView: View):RecyclerView.ViewHolder(itemView)
{
val title1:TextView
val title2:TextView
val title3:TextView
val title4:TextView
val title5:TextView
val title6:TextView
val title7:TextView
val title8:TextView
val title9:TextView
val title10:TextView
val title11:TextView
val title12:TextView
val img1:ImageView
val img2:ImageView
val img3:ImageView
val img4:ImageView
val img5:ImageView
val img6:ImageView
val img7:ImageView
val img8:ImageView
val img9:ImageView
val img10:ImageView
val img11:ImageView
val img12:ImageView
init {
title1 = itemView.findViewById(R.id.child_title1)
title2 = itemView.findViewById(R.id.child_title2)
title3 = itemView.findViewById(R.id.child_title3)
title4 = itemView.findViewById(R.id.child_title4)
title5 = itemView.findViewById(R.id.child_title5)
title6 = itemView.findViewById(R.id.child_title6)
title7 = itemView.findViewById(R.id.child_title7)
title8 = itemView.findViewById(R.id.child_title8)
title9 = itemView.findViewById(R.id.child_title9)
title10 = itemView.findViewById(R.id.child_title10)
title11 = itemView.findViewById(R.id.child_title11)
title12 = itemView.findViewById(R.id.child_title12)
img1 = itemView.findViewById(R.id.child_img1)
img2 = itemView.findViewById(R.id.child_img2)
img3 = itemView.findViewById(R.id.child_img3)
img4 = itemView.findViewById(R.id.child_img4)
img5 = itemView.findViewById(R.id.child_img5)
img6 = itemView.findViewById(R.id.child_img6)
img7 = itemView.findViewById(R.id.child_img7)
img8 = itemView.findViewById(R.id.child_img8)
img9 = itemView.findViewById(R.id.child_img9)
img10 = itemView.findViewById(R.id.child_img10)
img11 = itemView.findViewById(R.id.child_img11)
img12 = itemView.findViewById(R.id.child_img12)
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ChildHolder {
val mView = LayoutInflater.from(parent.context).inflate(R.layout.child_item, parent, false)
return ChildHolder(mView)
}
override fun onBindViewHolder(holder: ChildHolder, position: Int) {
val title1 = myChildList[position].title1
holder.title1.text = if (title1.length>10){
title1.substring(0,10)+"..."
}else{
title1
}
val title2 = myChildList[position].title2
holder.title2.text = if (title2.length>10){
title2.substring(1,10)+"..."
}else{
title2
}
val title3 = myChildList[position].title3
holder.title3.text= if (title3.length>10){
title3.substring(0,10)+"..."
}else{
title3
}
val title4 = myChildList[position].title4
holder.title4.text = if (title4.length>10){
title4.substring(0,10)+"..."
}else {
title4
}
val title5 = myChildList[position].title5
holder.title5.text = if (title5.length>10){
title5.substring(0,10)+"..."
}else{
title5
}
val title6 = myChildList[position].title6
holder.title6.text = if (title6.length>10){
title6.substring(0,10)+"..."
}else{
title6
}
val title7=myChildList[position].title7
holder.title7.text = if (title7.length>10){
title7.substring(0,10)+"..."
}else{
title7
}
val title8=myChildList[position].title8
holder.title8.text = if (title8.length>10){
title8.substring(0,10)+"..."
}else{
title8
}
val title9=myChildList[position].title9
holder.title9.text = if (title9.length>10){
title9.substring(0,10)+"..."
}else{
title9
}
val title10=myChildList[position].title10
holder.title10.text = if (title10.length>10){
title10.substring(0,10)+"..."
}else{
title10
}
val title11=myChildList[position].title11
holder.title11.text = if (title11.length>10){
title11.substring(0,10)+"..."
}else{
title11
}
val title12 =myChildList[position].title12
holder.title12.text = if (title12.length>10){
title12.substring(0,10)+"..."
}else{
title12
}
loadA. 导 言ndDisplayImage(myChildList[position].img1, holder.img1)
loadA. 导 言ndDisplayImage(myChildList[position].img2, holder.img2)
loadA. 导 言ndDisplayImage(myChildList[position].img3, holder.img3)
loadA. 导 言ndDisplayImage(myChildList[position].img4, holder.img4)
loadA. 导 言ndDisplayImage(myChildList[position].img5, holder.img5)
loadA. 导 言ndDisplayImage(myChildList[position].img6, holder.img6)
loadA. 导 言ndDisplayImage(myChildList[position].img7, holder.img7)
loadA. 导 言ndDisplayImage(myChildList[position].img8, holder.img8)
loadA. 导 言ndDisplayImage(myChildList[position].img9, holder.img9)
loadA. 导 言ndDisplayImage(myChildList[position].img10, holder.img10)
loadA. 导 言ndDisplayImage(myChildList[position].img11, holder.img11)
loadA. 导 言ndDisplayImage(myChildList[position].img12, holder.img12)
holder.img1.setOnClickListener {
loadA. 导 言ndDisplayProfile(myChildList[position].userid1, holder.img1.context)
}
holder.img2.setOnClickListener {
loadA. 导 言ndDisplayProfile(myChildList[position].userid2, holder.img2.context)
}
holder.img3.setOnClickListener {
loadA. 导 言ndDisplayProfile(myChildList[position].userid3, holder.img3.context)
}
holder.img4.setOnClickListener {
loadA. 导 言ndDisplayProfile(myChildList[position].userid4, holder.img4.context)
}
holder.img5.setOnClickListener {
loadA. 导 言ndDisplayProfile(myChildList[position].userid5, holder.img5.context)
}
holder.img6.setOnClickListener {
loadA. 导 言ndDisplayProfile(myChildList[position].userid6, holder.img6.context)
}
holder.img7.setOnClickListener {
loadA. 导 言ndDisplayProfile(myChildList[position].userid7, holder.img7.context)
}
holder.img8.setOnClickListener {
loadA. 导 言ndDisplayProfile(myChildList[position].userid8, holder.img8.context)
}
holder.img9.setOnClickListener {
loadA. 导 言ndDisplayProfile(myChildList[position].userid9, holder.img9.context)
}
holder.img10.setOnClickListener {
loadA. 导 言ndDisplayProfile(myChildList[position].userid10, holder.img10.context)
}
holder.img11.setOnClickListener {
loadA. 导 言ndDisplayProfile(myChildList[position].userid11, holder.img11.context)
}
holder.img12.setOnClickListener {
loadA. 导 言ndDisplayProfile(myChildList[position].userid12, holder.img12.context)
}
}
override fun getItemCount(): Int {
return myChildList.size
}
private fun loadA. 导 言ndDisplayImage(imageUrl: String, imageView: ImageView) {
if (imageUrl.isNotEmpty()) {
try {
Glide.with(imageView.context)
.asBitmap()
.load(imageUrl)
.placeholder(R.drawable.male_avatar)
.circleCrop()
.diskCacheStrategy(DiskCacheStrategy.A. 导 言LL)
.into(imageView)
} catch (e: Exception) {
e.printStackTrace() // Handle any exceptions that may occur during the loading process
}
} else {
Glide.get(imageView.context).clearDiskCache()
}
}
private fun loadA. 导 言ndDisplayProfile(uid: Int, cntxt: Context) {
val bundle = Bundle()
bundle.putInt("userId", uid)
val fragment = ProfileViewPeople.newInstance(uid).apply {
arguments = bundle
}
val appCompatA. 导 言ctivity = cntxt as A. 导 言ppCompatA. 导 言ctivity
appCompatA. 导 言ctivity.supportFragmentManager.beginTransaction()
.setCustomA. 导 言nimations( R.anim.slide_in_right,
R.anim.slide_out_left, R.anim.slide_in_left, R.anim.slide_out_right )
.replace(R.id.peopleNearBy, fragment).addToBackStack("selectx")
.commit()
}
}
序言:
@ExperimentalCoroutinesA. 导 言pi
class ParentA. 导 言dapter(private val context: Context, var parentList:A. 导 言rrayList<PeopleNearByModelClass>):RecyclerView.A. 导 言dapter<ParentA. 导 言dapter.ParentHolder>() {
private lateinit var childA. 导 言dapter:ChildA. 导 言dapter
class ParentHolder(itemView:View):RecyclerView.ViewHolder(itemView){
//val title:TextView
val mRecyclerView:RecyclerView
init {
//title = itemView.findViewById(R.id.parent_title)
mRecyclerView = itemView.findViewById(R.id.child_recyclerview)
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ParentHolder {
val mView = LayoutInflater.from(parent.context).inflate(R.layout.parent_item, parent, false)
return ParentHolder(mView)
}
override fun onBindViewHolder(holder: ParentHolder, position: Int) {
childA. 导 言dapter = ChildA. 导 言dapter(parentList[position].movieList)
holder.mRecyclerView.layoutManager =
LinearLayoutManager(context, LinearLayoutManager.HORIZONTA. 导 言L, false)
holder.mRecyclerView.adapter = childA. 导 言dapter
if ( position == 0) {
val template =
holder.itemView.findViewById<TemplateView>(R.id.my_template)
template.visibility = View.GONE
}
else if (size == position) {
val template =
holder.itemView.findViewById<TemplateView>(R.id.my_template)
template.visibility = View.GONE
}
else {
MobileA. 导 言ds.initialize(context) {
val adLoader: A. 导 言dLoader =
A. 导 言dLoader.Builder(context, "ca-app-pub-3940256099942544/2247696110")
.forNativeA. 导 言d { nativeA. 导 言d ->
// if (isDestroyed) {
// nativeA. 导 言d.destroy()
// return
// }
val styles = NativeTemplateStyle.Builder().build()
val template =
holder.itemView.findViewById<TemplateView>(R.id.my_template)
template.setStyles(styles)
template.visibility = View.VISIBLE
template.setNativeA. 导 言d(nativeA. 导 言d)
}
.withA. 导 言dListener(object : A. 导 言dListener() {
override fun onA. 导 言dFailedToLoad(adError: LoadA. 导 言dError) {
}
})
.withNativeA. 导 言dOptions(
NativeA. 导 言dOptions.Builder()
.build()
)
.build()
adLoader.loadA. 导 言d(A. 导 言dRequest.Builder().build())
}
}
}
override fun getItemCount(): Int {
return parentList.size
}
}
PEOPLENEA. 导 言RBY FRA. 导 言GMENT CODE FOR NESTED RECYCLER VIEW:
private suspend fun loopA. 导 言rray(peoplnearbylists:MutableList<List<PeopleNearByModelClass>>, lastarraysize: JSONA. 导 言rray) {
val lastA. 导 言rrayList = lastarraysize
val totalSize = peoplnearbylists.size
val rowLists = peoplnearbylists
// val totalsize = peoplnearbylists.size
for (index in 0 until totalSize) {
val rowList = rowLists[index]
val maxUsers = minOf(rowList.size, 12) // Update the maximum number of users per row
val uniqueUserSet = HashSet<String>() // Track unique user names
val peopleList = mutableListOf<Peoples>()
for (i in 0 until maxUsers step 12) {
val person1 = rowList[i]
val person2 = rowList[i + 1]
val person3 = rowList[i + 2]
val person4 = rowList[i + 3]
val person5 = rowList[i + 4]
val person6 = rowList[i + 5]
val person7 = rowList[i + 6]
val person8 = rowList[i + 7]
val person9 = rowList[i + 8]
val person10 = rowList[i + 9]
val person11 = rowList[i + 10]
val person12 = rowList[i + 11]
peopleList.add(
Peoples(
title1 = person1.userName,
img1 = person1.userImage,
userid1 = person1.userID,
title2 = person2.userName,
img2 = person2.userImage,
userid2 = person2.userID,
title3 = person3.userName,
img3 = person3.userImage,
userid3 = person3.userID,
title4 = person4.userName,
img4 = person4.userImage,
userid4 = person4.userID,
title5 = person5.userName,
img5 = person5.userImage,
userid5 = person5.userID,
title6 = person6.userName,
img6 = person6.userImage,
userid6 = person6.userID,
title7 = person7.userName,
img7 = person7.userImage,
userid7 = person7.userID,
title8 = person8.userName,
img8 = person8.userImage,
userid8 = person8.userID,
title9 = person9.userName,
img9 = person9.userImage,
userid9 = person9.userID,
title10 = person10.userName,
img10 = person10.userImage,
userid10 = person10.userID,
title11 = person11.userName,
img11 = person11.userImage,
userid11 = person11.userID,
title12 = person12.userName,
img12 = person12.userImage,
userid12 = person12.userID
)
)
}
mParentList.add(Parent("", peopleList))
}
mA. 导 言dapter = ParentA. 导 言dapter(requireContext(), mParentList, totalSize)
withContext(Dispatchers.Main) {
mRecyclerView.layoutManager = LinearLayoutManager(requireContext())
mRecyclerView.adapter = mA. 导 言dapter
}
}
A. 导 言