1
Save list! Next, I have an Activity where I call a Fragment using
// ...
val manager = supportFragmentManager
val transaction = manager.beginTransaction()
_Fragment = AcvtFragmentView()
val args = Bundle()
args.putBoolean("cal_warning", true)
args.putString("ID", ID)
args.putString("name", kName)
args.putString("email", kEmail)
args.putString("date", date)
args.putString("time", time)
args.putString("keypub", keypub)
args.putString("msg", interpretation)
_Fragment!!.setArguments(args)
transaction.replace(R.id.fragmentview, _Fragment!!)
transaction.addToBackStack(null)
transaction.commit()
// ...
It’s working well, but what happens is that when it opens on the screen of this Activity and I click on any Textview inside this fragment it closes alone and I need to type text in these fields. I’ve been all over the Internet.
I wonder if anyone here could help me with this?
Thanks
Follows the code of Activity Acvtfragmenteview:
class AcvtFragmentView : Fragment() {
// ...
internal var actionCallBack: onActionEventListener? = null
interface onActionEventListener {
fun dlgActions(id: Int,name: String?,email: String?,datepub: String?,interpretation: String?)
}
override fun onAttach(context: Context) {
super.onAttach(context)
mContext = context
try {
actionCallBack = context as onActionEventListener
} catch (e: ClassCastException) {
throw ClassCastException("$activity must implement onSomeEventListener")
}
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
mydb = DreamsItemHelper(mContext)
}
override fun onCreateView(inflater: LayoutInflater,container: ViewGroup?,savedInstanceState: Bundle?): View? {
window = inflater.inflate(R.layout.layout_interprete, container, false)
val ID = arguments!!.getString("ID")
val dDate = arguments!!.getString("date")
val tTime = arguments!!.getString("time")
val keypub = arguments!!.getString("keypub")
val interp = arguments!!.getString("msg")
date = window!!.findViewById<View>(R.id.datepubItView) as TextView
date!!.text = dDate
val kName = arguments!!.getString("name")
val kEmail = arguments!!.getString("email")
val name = window!!.findViewById<View>(R.id.interName) as EditText
name.setText(kName)
val email = window!!.findViewById<View>(R.id.interEmail) as EditText
email.setText(kEmail)
interpretation = window!!.findViewById<View>(R.id.edtInterpretation) as EditText
interpretation!!.text = interp
btnsend = window!!.findViewById<View>(R.id.btnSendToInterpret) as TextView
if (interp != null) {
btnsend!!.isEnabled = false
}
btnsend!!.setOnClickListener {
val c = Calendar.getInstance()
val iName = name.text.toString()
val iEmail = email.text.toString()
val aDay = fillLeft(c.get(Calendar.DAY_OF_MONTH).toString(), "0")
val aMonth = fillLeft((c.get(Calendar.MONTH) + 1).toString(), "0")
val aYear = fillLeft(c.get(Calendar.YEAR).toString(), "0")
val lang = Locale.getDefault().language
var dateGlobal = ""
when (lang.toLowerCase()) {
"en" -> dateGlobal = aYear + "-" + aMonth + "-" + aDay
"es" -> dateGlobal = aDay + "-" + aMonth + "-" + aYear
"pt" -> dateGlobal = aDay + "-" + aMonth + "-" + aYear
}
val inter = (interpretation as EditText).text.toString()
val id = Integer.valueOf(ID!!)
val isOk = !iName.equals("") && !iEmail.equals("") && iEmail.contains("@") && iEmail.contains(".")
if (isOk)
SendToInterpret().execute(ID,iName,iEmail,qDate,tTime,keypub,dateGlobal,inter
)
else
Toast.makeText(mContext,getString(R.string.toastNameAndEmailEmpty),Toast.LENGTH_LONG).show()
}
val btnclose = window!!.findViewById<View>(R.id.btnCloseInterpret) as TextView
btnclose.setOnClickListener { setGone() }
window!!.requestLayout()
return window
}
Since you are using Kotlin, take a look at the View Binding plugin of Android Extensions, with it you no longer need
findViewById, just call the view by its Id in the layout (at the appropriate time, in this case,onViewCreated) https://kotlinlang.org/docs/tutorials/android-plugin.html– Lennoard Silva