-1
class HomeFragment : Fragment() {

var sampleImage  = intArrayOf(
        R.drawable.Tokyo,
        R.drawable.Kenya,
        R.drawable.Newyork
)
var carouselView: CarouselView? = null
override fun onCreateView(
    inflater: LayoutInflater, container: ViewGroup?,
    savedInstanceState: Bundle?
): View? {
    // Inflate the layout for this fragment
    return inflater.inflate(R.layout.fragment_home, container, false)
    carouselView =findViewById(R.id.carouselview)

    carouselView!!.pageCount = sampleImage.size

    carouselView!!.setImageListener(imageListener)

}

var imageListener  = ImageListener { position, imageView -> imageView.setImageResource(sampleImage
        [ position]) }

}

niqueco
  • 2,261
  • 19
  • 39

2 Answers2

0

You can use view.findViewById() inside fragments for finding views.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Amirhosein
  • 1,048
  • 7
  • 19
0

It is not releated to kotlin. So findViewById is a part of View, We can use findViewById if the class is extending AppCompactActivity because AppCompactActivity extends View. So Fragment doesn't extend them, We load our fragment XML from onCreateView which returns a View Instance, And we can use that View instance to call findViewByID
Cut Story Short use view.findViewById() To Know more

Swapnil Padaya
  • 687
  • 5
  • 14