How to pick an image from imageslide show as wallpaper | Android Studio |Kotlin

22 Views Asked by At

I am trying to pick an image from a slide show as my wallpaper by double clicking on it...however it's not working.This is my code I still new to android studio

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val imageSlider = findViewById<ImageSlider>(R.id.image_slider) // init imageSlider

        val imageList = ArrayList<SlideModel>() // Create image list
        imageList.add(SlideModel(drawable.mohamed_1))
        imageList.add(SlideModel(drawable.mohamed_2))
         var currentimageList = 0


        //private var currentWallpaperIndex = 0
        imageSlider.setImageList(imageList, ScaleTypes.FIT)

        //imageSlider.setSlideAnimation(AnimationTypes.ZOOM_OUT)

        imageSlider.setItemClickListener(object : ItemClickListener {
            override fun onItemSelected(position: Int) {
                // You can listen here.
                //Toast.makeText(applicationContext, "item" + position +  "selected", Toast.LENGTH_LONG).show()
            }

            override fun doubleClick(position: Int) {
                // Do not use onItemSelected if you are using a double click listener at the same time.
                // Its just added for specific cases.
                // Listen for clicks under 250 milliseconds.
                //Toast.makeText(applicationContext, "double", Toast.LENGTH_LONG).show()
                Toast.makeText(applicationContext, "item" + position +  "selected", Toast.LENGTH_LONG).show()
                //Now this object has everything you need to get

                val wallpaperManager = WallpaperManager.getInstance(applicationContext)
                wallpaperManager.setResource(position)

            }
        })
0

There are 0 best solutions below