У меня есть фрагмент действия, в котором он вызывает значения из отдельного класса данных, а также файл. xml
Я хочу, чтобы кнопка в файле. xml была доступна в Kotlin CLASS. Однако ошибка продолжает показывать, что объявленная функция недоступна. Что я сделал:
страница класса kotlin:
class HomeFragment : Fragment() {
private val personcolletionref =Firebase.firestore.collection( "users")
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_home, container, false)
submitbutton.setOnClickListener {
}
}
private fun savePerson (person: Person) = CoroutineScope(Dispatchers.IO).launch {
try {
personcolletionref.add(person).await()
withContext(Dispatchers.Main) {
Toast.makeText(activity, "Successful", Toast.LENGTH_LONG).show()
}
}catch (e: Exception) {
withContext(Dispatchers.Main) {
Toast.makeText(activity, e.message, Toast.LENGTH_LONG).show()
}
}
}
}
кнопка в файле xml, которую нужно вызвать:
<Button
android:id="@+id/submitbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="268dp"
android:text="Submit"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/edittextage"
app:layout_constraintStart_toStartOf="@+id/edittextage" />