OK sorry me again, with some not great code from a...
# android
b
OK sorry me again, with some not great code from a course (they are slowly sorting out code to show problems and how to make it better).
Copy code
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
    Log.d(TAG, "getView called pos $position")

    // if convertView is null inflate it otherwise use it
    val view =
        if (convertView == null) {
            Log.d(TAG,"getView called with null convertView")
            inflater.inflate(resource, parent, false)
        } else {
            Log.d(TAG,"getView privided a convertView")
            convertView
        }

    val tvName: TextView = view.findViewById(R.id.tvName)
    val tvArtist: TextView = view.findViewById(R.id.tvArtist)
    val tvSummary: TextView = view.findViewById(R.id.tvSummary)

    val currentApp = applications[position] // position from constructor

    tvName.text = currentApp.name
    tvArtist.text = currentApp.artist
    tvSummary.text = currentApp.summary

    return view
}
Its the 'val view =' bit I have a question about. I get what it is doing, i.e. only running the inflator if needed. What I don't get is why when the method is run again convertView is set. i.e. when is convertView set to view?
😶 4
e
ConvertView is passed in as an argument. Whoever is responsible for calling getView is probably reusing the view returned from the previous call
👍 1
b
OK, thanks, that makes sense.