在學習kotlin之前,我們都知道獲取kotlin的控件,只要在代碼中輸入對應的Id就行了。但是,對於fragment確並不適用。那在fragment怎麼獲取控件呢?
<android.support.v7.widget.RecyclerView
android:id="@+id/homeRecycleView"
android:layout_below="@id/imageCycleView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView>
獲取方式:
homeRecycleView = Companion.view?.findViewById(R.id.homeRecycleView) as RecyclerView;
當初,這個坑可是浪費了我不少時間。阿門!