【问题标题】:add in arraylist automaticlly and error while try to clear() arraylist [duplicate]尝试清除()arraylist时自动添加arraylist并出错[重复]
【发布时间】:2018-07-17 05:28:21
【问题描述】:

在我的模块中,我传递了 arraylist 投掷意图。但是当我打开我的活动时,它会自动添加。当我尝试在父活动的 onResume() 中清除我的数组列表时,似乎出现了这种类型的错误:-

应用程序的 PagerAdapter 更改了适配器的内容,而没有调用 PagerAdapter#notifyDataSetChanged!

我的代码在这里:-

这是PreExamActivity.kt这里是考试开始按钮的点击事件。

startExam.setOnClickListener {
        //getMarks()
        calculation()
        Common.examqueList = null
        if (numOfQueInSelectedChapter > totalQuestion) {
            val intent = Intent(this, ExamActivity::class.java)
            Common.examqueList = examQueList
            startActivity(intent)
        } else {
            Toast.makeText(this, "Check yr question", Toast.LENGTH_SHORT).show()
        }
    }

override fun onResume() {
    super.onResume()
    Common.examqueList?.clear()
}

这是我的 ExamActivity.kt** :-

    queArray = Common.examqueList
    val adpter: PagerAdapter = ExamQuestionPageView(this, queArray!!, question_img_path)
    qPager.adapter = adpter

【问题讨论】:

    标签: android arraylist kotlin android-viewpager


    【解决方案1】:

    清空ArrayList后调用notifyDataSetChanged。

    每当您从列表中添加/删除项目或修改列表的大小时,您必须调用 notifyDataSetChanged() 以查看回收器视图中的更改。

    override fun onResume() {
        super.onResume()
        Common.examqueList?.clear()
        adapter.notifyDataSetChanged();
    }
    

    【讨论】:

      猜你喜欢
      • 2018-05-25
      • 1970-01-01
      • 2018-08-12
      • 2020-11-05
      • 2019-05-12
      • 2017-07-17
      • 2016-10-31
      • 1970-01-01
      • 2022-01-19
      相关资源
      最近更新 更多