Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/214.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Can';t在刷卡期间更新ViewPager中的菜单项状态_Android_Kotlin_Android Viewpager_Androidimageslider - Fatal编程技术网

Android Can';t在刷卡期间更新ViewPager中的菜单项状态

Android Can';t在刷卡期间更新ViewPager中的菜单项状态,android,kotlin,android-viewpager,androidimageslider,Android,Kotlin,Android Viewpager,Androidimageslider,我的菜单中有我最喜欢的图标和ViewPager。当我单击该项目时,它会更改。但当我刷卡时,它不记得物品的状态 我已经实现了setOnPageChangeListener,并在onPageSelected中检查了项目的状态和更改的可绘图项 override fun onPageSelected(position: Int) { currentPage = position if (imageModelArrayList!![curr

我的菜单中有我最喜欢的图标和
ViewPager
。当我单击该项目时,它会更改。但当我刷卡时,它不记得物品的状态

我已经实现了
setOnPageChangeListener
,并在
onPageSelected
中检查了项目的状态和更改的可绘图项

override fun onPageSelected(position: Int) {

                currentPage = position
                if (imageModelArrayList!![currentPage].isFavourite == true) {
                    isExistInFavorite = true

                    menuItem?.icon =
                        ContextCompat.getDrawable(
                            applicationContext,
                            R.drawable.ic_favorite_black_24dp
                        )

                   helper.updateGreetingByID(true, id)

                } else {
                    isExistInFavorite = false
                    menuItem?.icon =
                        ContextCompat.getDrawable(
                            applicationContext,
                            R.drawable.ic_favorite_border_black_24dp
                        )
                    helper.updateGreetingByID(false, id)
                }

            }
这里是项目点击

R.id.action_favorite->{

            if (!isExistInFavorite) {
                greetingModel.id?.let { helper.updateGreetingByID(true, id) }
                menuItem?.icon =
                    ContextCompat.getDrawable(this, R.drawable.ic_favorite_black_24dp)
                Toast.makeText(
                    this@ImageDetailActivity,
                    "Favourite added",
                    Toast.LENGTH_SHORT
                ).show()
                isExistInFavorite = true

            } else {
                isExistInFavorite = false
                menuItem?.icon =
                    ContextCompat.getDrawable(this, R.drawable.ic_favorite_border_black_24dp)
                Toast.makeText(
                    this@ImageDetailActivity,
                    "favourite deleted",
                    Toast.LENGTH_SHORT
                ).show()
                greetingModel.id?.let { helper.updateGreetingByID(false, id) }
            }

            return true
        }
更改图标后,您可能需要拨打电话