Inflate layout programmatically within another layout

前端 未结 8 2031
心在旅途
心在旅途 2020-11-30 04:54

I need help with my android app. I need inflate a layout within another layout and I dont know how I do. My xml code is this:

  • item.xml - I need inflate mult

相关标签:
8条回答
  • 2020-11-30 05:12

    Kotlin code to do so:

     val layoutToInflate = 
     this.layoutInflater.inflate(R.layout.ly_custom_layout, 
      null)
    container_destacado.addView(layoutToInflate )
    
    0 讨论(0)
  • 2020-11-30 05:12

    in Kotlin with editable textview elements on item.xml

      val item = LayoutInflater.from(this).inflate(R.layout.item,null)
      val distance_N1_holder = item.findViewById<TextView>(R.id.distance_N1)
      distance_N1_holder.text = //dynamically generated value
    
      main.addView(item)
    
    0 讨论(0)
提交回复
热议问题