0

I'm trying to change height and width of ListView item programmatically, but I'm getting an "val cannot be reassigned error", can you please tell me witch exact val can't be reassigned here and how can I finally set height and width for List is my custom adapter?

    class Game6Adapter(
    private val mContext: Context,
    private val resourceLayout: Int,
    private val items: ArrayList<Drawable>
) : ArrayAdapter<Drawable>(mContext, resourceLayout, items) {

    override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
        var v: View? = convertView

        var vi: LayoutInflater = LayoutInflater.from(mContext)
        v = vi.inflate(resourceLayout, null)


        val p = getItem(position)


        var imageView = v!!.findViewById(R.id.game_6_item_image) as ImageView
        imageView.setImageDrawable(items[position])

        var layoutParams = parent.layoutParams
        imageView.height = (parent.height * 0.1).toInt() // val cannot be reassigned
        imageView.width = (parent.height * 0.1).toInt()  val cannot be reassigned
        imageView.requestLayout()


        return v!!
    }
}

1 Answers1

0

Fragmentary answer to your question:

The fields height and width inside imageView are immutable (val):

var imageView = v!!.findViewById(R.id.game_6_item_image) as ImageView

Since I don't know and don't see the implementation of the class/interface ImageView, I can't say how to achieve the change.

Neo
  • 1,869
  • 1
  • 7
  • 20