Search code examples
androidkotlinscrollview

Scrollview not showing views


I have an recyclerview where I show my data. Part of the recyclerviewitem is a scrollview. recyclerview design

So I fill the recyclerview with data and set a picture and text within the holder. I also want to add pictures to the scrollview there.

    override fun onBindViewHolder(holder: SchritteViewHolder, position: Int) {
        val current = schritte[position]

       holder.rezeptePicView.setImageDrawable( ContextCompat.getDrawable(context,current.alg.bild))
        var text = ""
        for( zut in zutatenforSchritte[position]) {
            val imageViewzut = ImageView(this.context)
            val textView = TextView(this.context)
            imageViewzut.setImageDrawable(ContextCompat.getDrawable(context,zut.bild))
            textView.text = zut.zutname
            text =text + zut.zutname
            holder.scrollViewSchritte.addView(imageViewzut)
            holder.scrollViewSchritte.addView(textView)
        }
        holder.rezepteItemView.text = current.alg.text + " " + current.sp.temperatur + " " +current.sp.zeit +" " + current.sp.sonst +text
    }

The data is there because I can fill it in the text an picture and text are there, but the scrollview stays empty. filled recyclerview

I have no idea why the scrollview stays empty. So if you know what could be the reasons tips would be nice.


Solution

  • So, scrollview waws the wrn gway to go. I added an other recyclerview just showing an icon.

    So the outer Recyclerview looks like this:

    class SchritteSmallListAdapterJustShow internal constructor(
        context: Context
    ): RecyclerView.Adapter<SchritteSmallListAdapterJustShow.SchritteViewHolder>(){
    
        private val inflater: LayoutInflater = LayoutInflater.from(context)
        private var schritte = emptyList<SpezSchrittWithAlg>()
        val contextfu = context
        private var zutatenforSchritte :MutableList<List<ZutatenData>> =emptyList<List<ZutatenData>>().toMutableList()
    
        inner class SchritteViewHolder(itemView : View): RecyclerView.ViewHolder(itemView){
            val rezepteItemView: TextView = itemView.findViewById(R.id.textSmallschritt)
            val rezeptePicView: ImageView = itemView.findViewById(R.id.imageViewschritt)
            var recycler: RecyclerView = itemView.findViewById(R.id.recyclerviewforIcons)
            val adapter = ZutatenIconShowAdapter(contextfu)
        }
    
        override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SchritteViewHolder {
            val itemView = inflater.inflate(R.layout.recyclerview_schritte, parent, false)
            return  SchritteViewHolder(itemView)
        }
    
        override fun onBindViewHolder(holder: SchritteViewHolder, position: Int) {
            val current = schritte[position]
    
           holder.rezeptePicView.setImageDrawable( ContextCompat.getDrawable(contextfu,current.alg.bild))
            holder.rezepteItemView.text = current.alg.text + " " + current.sp.temperatur + " " +current.sp.zeit +" " + current.sp.sonst
            holder.recycler.adapter = holder.adapter
            holder.recycler.layoutManager = LinearLayoutManager(contextfu, RecyclerView.HORIZONTAL, false)
            holder.recycler.layoutMode
            holder.adapter.setZutaten(zutatenforSchritte[position])
    
        }
    
        internal fun setSchritte(rez : List<SpezSchrittWithAlg>){
            schritte = rez
            notifyDataSetChanged()
        }
    
        internal fun setZutatenliste(zutaten  : MutableList<List<ZutatenData>>){
            zutatenforSchritte = zutaten
        }
    
        override fun getItemCount(): Int =schritte.size
    }
    

    And the inner Recyclerview looks like this:

    class ZutatenIconShowAdapter internal constructor(
        context: Context
    ): RecyclerView.Adapter<ZutatenIconShowAdapter.ZutatenViewHolder>(){
    
        private val inflater: LayoutInflater = LayoutInflater.from(context)
        private var zutaten = emptyList<ZutatenData>()
        private val context = context
    
        inner class ZutatenViewHolder(itemView : View): RecyclerView.ViewHolder(itemView){
            val rezeptePicView: ImageView = itemView.findViewById(R.id.smallIconview)
        }
    
        override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ZutatenViewHolder {
            val itemView = inflater.inflate(R.layout.recyclerview_just_icon, parent, false)
            return  ZutatenViewHolder(itemView)
        }
    
        override fun onBindViewHolder(holder: ZutatenViewHolder, position: Int) {
            val current = zutaten[position]
            holder.rezeptePicView.setImageDrawable( ContextCompat.getDrawable(context,current.bild))
    
        }
    
        internal fun setZutaten(zutats: List<ZutatenData>){
            zutaten= zutats
            notifyDataSetChanged()
        }
    
        override fun getItemCount(): Int =zutaten.size
    }
    

    Which got me the result I wanted: enter image description here