Question

Suppose I have several activities that all inherits from a same BaseActivity. I want to initialize some drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);. Each activity relies on some view as such

...#custom layout

When I put drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); in each activity, drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); in BaseActivity,I get some NullPointerException. Is there a way to get the view that was instantiated in some activity that inherits from CustomActivity

Était-ce utile?

La solution

What you can is the following. Let's call someMethod the protected method where you set drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); in the BaseActivity. Now, in some of the custom activities, call in the onCreate method someMethod where

protected void someMethod(){
        super.someMethod();
    }
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top