Fragment

In Android development, a Fragment is a modular section of an activity. A fragment has its own lifecycle, can handle its own input events, and can be added or removed while the activity is running. Fragments are used to create dynamic and flexible UI designs that can be adapted to different screen sizes and orientations.

Inside onelib, you just need to extend the BaseFragment and include the binding of the fragment's view. For example:

class TestFragment : BaseFragment<FragmentTestBinding>() {

    override fun getViewBinding(
        layoutInflater: LayoutInflater,
        container: ViewGroup?,
        attachRoot: Boolean
    ): FragmentTestBinding = FragmentTestBinding.inflate(layoutInflater)

    override fun initUI() {
        // Handle UI here, ex: set text of TextView, set adapter to RecyclerView, etc
    }

    override fun initAction() {
        // Handle Action here, ex: click button, etc
    }


    override fun initProcess() {
        // Handle Process here, ex: load data, etc
    }

    override fun initObservers() {
        // Handle Observers here, ex: LiveData, Flow, etc
    }

}

Last updated