如何在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/