Skip to content

setContentView not called if binding doesn't invoked #8

Description

@homayoonahmadi

Hi there!
I liked your library and appreciate that, but I have a problem :

I saw you put setContentView() function inside getValue() method of delegation function; So if we don't want to access any property of binding variable like binding.root, etc, then setContentView() never calls and we don't see anything in the view when we launch app.

So my question is: Why didn't you call setContentView in init block like this? Did you do this for a reason?
Cause in this case it's not necessary to use any of binding properties to make sure setContentView function calls.

init {
        @Suppress("UNCHECKED_CAST")
        lifecycle.addObserver(object : DefaultLifecycleObserver {
            override fun onCreate(owner: LifecycleOwner) {

                /**
                 * inflate View class
                 */
                val inflateMethod = bindingClass.getMethod("inflate", LayoutInflater::class.java)

                /**
                 * Bind layout
                 */
                val invokeLayout = inflateMethod.invoke(null, activity.layoutInflater) as T

                /**
                 * Set the content view
                 */
                activity.setContentView(invokeLayout.root)

                binding = invokeLayout
            }
        })
    }

Thanks in advance.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions