0

I want to start a ringtone as soon as a specific condition is true. Exactly in a Viewholder class in a Fragment. In this class some data from a database are given to some textfields. Is a condition in this routine is true then a ringtone should be played. F.i.

   class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {

    fun bind(cryptoData: CryptoData, listener: Listener, icons: Array<Int>, position: Int) {

        itemView.setOnClickListener { listener.onItemClick(cryptoData) }
        itemView.icon_view.setImageResource(icons[position])
        itemView.text_name.text = cryptoData.name
        itemView.text_price.text = getPricesString(cryptoData.prices)

        val priceLimit = 6000.0
        val priceEuro = getPricesString(cryptoData.prices).toFloat()
        if(priceEuro > priceLimit){
          // ringtone should start here !!!
        }

    }

Many thanks for your answers best regards Peter

notstrom
  • 1
  • 1
  • I found [this](https://stackoverflow.com/questions/2618182/how-to-play-ringtone-alarm-sound-in-android) seaching "inurl:stackoverflow play ringtone" – Benoit Guina Apr 17 '20 at 20:21
  • Hello Benoit, Thanks for your hint, but that's not what I'm looking for. Playing a ringtone is not a problem. My problem is how I can set an action in the ViewHolder class that sends a signal to my app. Here I used the ringtone as an action. For example, this can also be replaced by a toast. The problem is still there. I am unable to send a toast within the ViewHolder class. Perhaps you have solutions to this. Thanks a lot Peter – notstrom Apr 18 '20 at 21:29
  • Why are you stuck? Are you missing the [Context](https://developer.android.com/reference/android/support/v7/widget/RecyclerView.ViewHolder#itemview)? `if(priceEuro > priceLimit) Toast.makeText(itemView.context, "hello", Toast.Long).show()` – Benoit Guina Apr 18 '20 at 21:54

0 Answers0