kotlin中 在fragment中不能像activity中直接通过id调用控件了,有什么办法吗
3条回答 默认 最新
- metgo 2017-07-20 10:21关注
在fragment中复写这个 onCreateView的时候实例化view,用view去findViewById,语法可以参考下边的
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? { val view = inflater!!.inflate(R.layout.xxxx, container, false) val iv_card = view.findViewById(R.id.xxxx) as ImageView iv_card.setImageResource(xxxxxxxxx]) return view }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报