문제

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

도움이 되었습니까?

해결책

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();
    }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top