Мне нужно изменить содержимое двух отдельных макетов внутри класса CardStackAdapter
ниже.
Проблема в том, что CardStackAdapter
раздувает заданный c макет (R.layout.item_spot
), и в коде мне нужно изменить два макета.
Я пробовал надувать и устанавливать содержание, код прокомментирован ниже, но ничего не изменилось в моем макете. Что еще мне делать?
import android.content.Context
import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import android.widget.Toast
import androidx.core.content.ContextCompat.startActivity
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.daimajia.slider.library.SliderAdapter
import com.daimajia.slider.library.SliderLayout
import com.daimajia.slider.library.SliderTypes.TextSliderView
import com.google.android.material.button.MaterialButton
import com.smarteist.autoimageslider.SliderView
import com.squareup.picasso.Picasso
class CardStackAdapter(
private var spots: List<Spot> = emptyList()
) : RecyclerView.Adapter<CardStackAdapter.ViewHolder>() {
private var context: Context? = null
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val inflater = LayoutInflater.from(parent.context)
context = parent.context
return ViewHolder(inflater.inflate(R.layout.item_spot, parent, false))
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val spot = spots[position]
//*** Here is the code I tried. It says the text was set, but nothing was changed in my layout.
// How would I go about doing this?
val inflater = LayoutInflater.from(context)
val t = inflater.inflate(R.layout.swipe_fragment, null, false)
val h = t.findViewById<TextView>(R.id.height_text)
h.text = spot.height
holder.name.text = spot.name + " "
holder.age.text = spot.age
holder.height.text = spot.height
holder.school.text = spot.school
val sliderView = holder.sliderView
sliderView.sliderAdapter = AndrewSliderAdapter(context, spot.images)
sliderView.isAutoCycle = false
holder.prevButton.setOnClickListener {
sliderView.currentPagePosition = holder.sliderView.currentPagePosition - 1
}
holder.nextButton.setOnClickListener {
sliderView.currentPagePosition = holder.sliderView.currentPagePosition + 1
}
holder.profileButton.setOnClickListener {
println("Profile Clicked")
val intent = Intent(this@CardStackAdapter.context, ViewOtherProfile::class.java)
intent.putExtra("uid", spot.uid)
context!!.startActivity(intent)
}
holder.profileButton.bringToFront()
// Deal with the sliderView
}
override fun getItemCount(): Int {
return spots.size
}
fun setSpots(spots: List<Spot>) {
this.spots = spots
}
fun getSpots(): List<Spot> {
return spots
}
class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val name: TextView = view.findViewById(R.id.item_name)
val age: TextView = view.findViewById(R.id.item_age)
val height: TextView = view.findViewById(R.id.item_height)
var school: TextView = view.findViewById(R.id.item_school)
var prevButton: MaterialButton = view.findViewById(R.id.prevButton)
var nextButton: MaterialButton = view.findViewById(R.id.nextButton)
var profileButton: LinearLayout = view.findViewById(R.id.profile_layout_click)
var sliderView: SliderView = view.findViewById(R.id.imageSlider)
}
}