Add multiple element in same page
Paul75 opened this issue · comments
Hello,
It is possible to have in one page and send to activity two elements ?
Exemple :
- stars
- EditText
When can I do this ?
thanks
Sorry I don't understand what you mean by that. The pages are just defined by XML attributes, all it really is, is a Fragment. So yes, you can put whatever UI elements you want, into it.
Yes, it is just a normal intent that you are returning to the calling activity. It works the same way as any other activity that provides a result.
yes but means I must do in onclicklistener on my ratingBar ? and on addTextChangedListener for the EditText ?
like :
findViewById<BaseRatingBar>(R.id.rating).setOnRatingChangeListener { baseRatingBar: BaseRatingBar, fl: Float ->
val resultData = Intent()
resultData.putExtra(RESULT_DATA_STARS, fl)
setResult(Activity.RESULT_OK, resultData)
}
findViewById<AppCompatEditText>(R.id.editComment).addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(p0: Editable?) {
val resultData = Intent()
resultData.putExtra(RESULT_DATA_COMMENT, p0.toString())
setResult(Activity.RESULT_OK, resultData)
}
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
}
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
}
})
Thanks
You can only set the result once, and you need to include both pieces of data in the intent. I think that you should look up some information on getting the result from the activity. My library does not do it any differently than a generic Android Activity
. It uses the exact same system.
https://developer.android.com/training/basics/intents/result
val resultData = Intent()
resultData.putExtra(RESULT_DATA_STARS, stars)
resultData.putExtra(RESULT_DATA_COMMENT, editComment.text.toString())
setResult(Activity.RESULT_OK, resultData)
strenge that when I do in the my post works I retreive all the two element ...