Android Kotlin : Load all images from assets folder dynamically

November 23, 2018 , , , 0 Comments

Hello Friends,

today we learn About Get All items from Assets folder to Folder,
How to Get All Item from dynamically,







private fun getStickers(stickerPackIndex: Int) {

    when(stickerPackIndex) {

        1 -> {
            var imgPath: Array<String>? = assets.list("person")

            if (imgPath != null) {
                for (i in imgPath.indices) {
                    var inputstream: InputStream = assets.open("person/" + (i-1) + ".png")
                    var bitmap: Bitmap = BitmapFactory.decodeStream(inputstream)
                    var sticker = StickersModel(bitmap)

                    stickerList += sticker
                }
            }
        }

        2 -> {
            var imgPath: Array<String>? = assets.list("message")

            if (imgPath != null) {
                for (i in imgPath.indices) {
                    var inputstream: InputStream = assets.open("message/" + (i-1) + ".png")
                    var bitmap: Bitmap = BitmapFactory.decodeStream(inputstream)
                    var sticker = StickersModel(bitmap)

                    stickerList += sticker
                }
            }
        }

    }

}


Contributer

Some say he’s half man half fish, others say he’s more of a seventy/thirty split. Either way he’s a fishy bastard. Google

0 comments:

Popular Posts