【发布时间】:2021-10-13 19:05:07
【问题描述】:
即使我已经初始化了绑定,我也遇到了绑定问题,但它无法识别它。我同时启用了 dataBinding 和 viewBinding。
这是我的代码片段
class QuizQuestionActivity : AppCompatActivity(), View.OnClickListener {
private lateinit var binding: ActivityQuizQuestionBinding
private var mCurrentPosition: Int = 1 // Default and the first question position
private var mQuestionsList: ArrayList<Question>? = null
private var mSelectedOptionPosition: Int = 0
private var mCorrectAnswers: Int = 0
// TODO (STEP 3: Create a variable for getting the name from intent.)
// START
private var mUserName: String? = null
// END
/**
* This function is auto created by Android when the Activity Class is created.
*/
override fun onCreate(savedInstanceState: Bundle?) {
//This call the parent constructor
super.onCreate(savedInstanceState)
binding = ActivityQuizQuestionBinding.inflate(layoutInflater)
// This is used to align the xml view to this class
setContentView(R.layout.activity_quiz_question)
// TODO (STEP 4: Get the NAME from intent and assign it the variable.)
// START
mUserName = intent.getStringExtra(Constants.USER_NAME)
// END
mQuestionsList = Constants.getQuestions()
setQuestion()
binding.tvOptionOne.setOnClickListener(this)
binding.tvOptionTwo.setOnClickListener(this)
binding.tvOptionThree.setOnClickListener(this)
binding.tvOptionFour.setOnClickListener(this)
binding.btnSubmit.setOnClickListener(this)
}
我的 gradle 文件片段
buildFeatures {
dataBinding = true
viewBinding = true
}
【问题讨论】:
标签: android kotlin data-binding