引入kotlin-android-extensions插件可以省去在代码中写view.findViewById的麻烦。但需要注意的是,kotlinx.android.synthetic工作的原理是getView().findViewById,所以如果当前位置getView的返回值不等于view,那用kotlinx.android.synthetic可能会返回一个空对象。
getView的说明:
Get the root view for the fragment’s layout (the one returned by onCreateView), if provided.
在onCreateView中测试,
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?