So I have a fragment that I need to be able to always update the text.
The text fields are:
- Song
- Artist
In my MainActivity I have a http request that keeps ping the server and getting the latest information.
That updates a global Class
package com.drn1.drn1
object DataHolder {
private var Song = ""
fun set_Song(s: String) {
Song = s
}
fun get_Song(): String {
return Song
}
private var Artist = ""
fun set_Artist(s: String) {
Song = s
}
fun get_Artist(): String {
return Artist
}
private var MDIA = "http://stream.radiomedia.com.au:8003/stream"
fun set_Media(s: String) {
MDIA = s
}
fun get_Media(): String {
return MDIA
}
}
The issue is I can't re-set the text in the fragment
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
//val context = inflater.context
//binding = MplayerBinding.inflate(com.drn1.drn1.R.layout.fragment_mplayer)
val root: View = inflater.inflate(R.layout.fragment_mplayer, container, false)
val btn = root.findViewById(R.id.mPlayPP) as ImageButton
val SG = root.findViewById(R.id.song) as TextView
SG.setText(Song)
}
Wondering what is the correct way to do this?