, , . , , , . , FRAGMENT
ACTIVITY
.
; INTERFACE
, ACTIVITY
, FRAGMENT
, , LAYOUT
.
: Kotlin, , Java, .
CALLBACK
.
interface ConcessionSelection {
fun selectConcession(view : View)
}
: , class ACTIVITY: AppCompatActivity(), INTERFACE
class ACTIVITY: AppCompatActivity(), FRAGMENT.INTERFACE
CALLBACK
.
class ACTIVITY : AppCompatActivity(), INTERFACE {
...
override fun CALLBACK (view: View) {
Log.i("ACTIVITY:CALLBACK","Activity Callback")
}
...
}
.
class FRAGMENT : Fragment() {
private var listener: ACTIVITY? = null
...
override fun onAttach(context: Context) {
super.onAttach(context)
if (context is ACTIVITY) {
listener = context
} else {
throw RuntimeException(context.toString() + " must implement OnFragmentInteractionListener")
}
}
override fun onDetach() {
super.onDetach()
listener = null
}
...
}
CALLBACK
<...>
...
<Button
android:id="@+id/button"
android:text="Button"
android:onClick="CALLBACK"/> # Usually highlighted in red by IDE since this is resolved at runtime.
...
</...>
: , , , .
, , CALLBACK
FRAGMENT
, ACTIVITY
. FRAGMENT
onClickListener
listener
, ACTIVITY
, . Android IDE, , , CALLBACK
, ACTIVITY
INTERFACE
, XML. CALLBACK
, , , , ListFragment
onItemSelected
.
The example onButtonPressed
provided by the template looks simple and does not provide a very useful implementation. Perhaps the Android site has a guide that explains how to intercept events and redirect to this method.