I want to pass multiple EditText values from RecyclerView to main Activity. I used BroadcastReceiver to handle this. And addTextChangedListener is used to get the changing text from the EditText. Here I shared my code. Please check and suggest me a solution.
Adapter code:
holder.textBox.addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(p0: Editable?) {
var texts = ArrayList<String>()
texts.add(p0.toString())
val intent = Intent("custom-message")
intent.putStringArrayListExtra("quantity", texts)
LocalBroadcastManager.getInstance(context).sendBroadcast(intent)
}
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {}
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {}
})
MainActivity code:
val broadCastReceiver = object : BroadcastReceiver() {
override fun onReceive(contxt: Context?, intent: Intent?) {
qty = intent!!.getStringArrayListExtra("quantity")
Log.d("broadCastReceiver", qty.toString())
}
}
LocalBroadcastManager.getInstance(this)
.registerReceiver(broadCastReceiver, IntentFilter("custom-message"))
Just use a callback function.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.