Frage

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

War es hilfreich?

Lösung

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();
    }
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top