Create Android App) Questions about storing hashtags in the Firebase database

Asked 2 years ago, Updated 2 years ago, 144 views

Hello, everyone~

I'm asking you because I'm blocked from implementing hashtags in the app I'm creating and saving them in the database.<

You want to save the tag in the Firebase with the same structure as above. (key:String, value:Boolean)

//Receive and remove tags
var tags = addphoto_tag_plants.text.toString()
var tagArray = tags.split(" ")

(Interim omitted)

storageRef?.putFile(photosUri!!.getItemAt(i).uri)?.continueWithTask { task: Task<UploadTask.TaskSnapshot> ->
return@continueWithTask storageRef.downloadUrl
}?.addOnSuccessListener { uri ->

//Matching data
contentDTO.imageUrl = uri.toString()
contentDTO.uid = auth?.currentUser?.uid //User's UID

....
(Interim omitted)
...

//Question part
for (i in 0 until tagArray.size) {
    contentDTO.tag[tagArray[i]] = true
}


savepath?.set(contentDTO)
setResult(Activity.RESULT_OK)
finish()
}

(The tag of the contentDTO data class is MutableMap = HashMap()

If there is only one tag entered, contentDTO.tag[tagname] = true You can do it like this

If you have multiple tags entered While going around tagArray, I received the 0th to ith key and contentDTO.I need to save it in tag How do I write the code? I look forward to hearing from the masters...

kotlin android hashtag firebase

2022-09-21 21:25

1 Answers

class ContentDTO {
    val tag: MutableMap<String, Boolean> = HashMap<String, Boolean>();
}

fun main(args: Array<String>) {
    val contentDTO = ContentDTO();
    var tagArray = "kotlin android hashtag firebase".split(" ")
    tagArray.associateTo(contentDTO.tag) {it to true}

    println(contentDTO.tag)
}


2022-09-21 21:25

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.