gpt4 book ai didi

android - 如何在 kotlin 中将 View 对象转换为我的布局

转载 作者:行者123 更新时间:2023-11-29 23:16:54 25 4
gpt4 key购买 nike

如何在setAnswer函数中访问page.questionTextView

//Create the given page (indicated by position)
override fun instantiateItem(container: ViewGroup, position: Int): Any {
val page = inflater.inflate(R.layout.layout_question, null)
page.questionTextView.text = "hi"

//Add the page to the front of the queue
(container as ViewPager).addView(page, 0)
return page
}

private fun setAnswer(page: View){
//how to access page.questionTextView
}

最佳答案

我找到了解决方案:我使用“with”方法访问 page.questionTextView

private fun setAnswer(page: View){
with(page){
questionTextView.text = "hi"
}
}

关于android - 如何在 kotlin 中将 View 对象转换为我的布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55163942/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com