What you are doing can't work because you are calling findViewById
before setting the contentview. This means you are trying to access elements within the Layout of your Activity before you even set the Layout or in other words, you are calling View.findViewById
before initializing your View.
Also, as far as I know, you have to call super.onCreate
in your Activity. You are not doing this. You call super.onCreate
in your TestActivity
but you have to call it in your BaseActivity
.
I haven't been working with AB for several Activities, but I would suggest to do the following:
BaseActivity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
void initDrawer(){
// put everything you have in your onCreate in here:
try {
// R.id.drawer_layout should be in every activity with exactly the same
// id.
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
drawerToggle = new ActionBarDrawerToggle((Activity) this, drawerLayout,
R.drawable.ic_drawer, 0, 0) {
public void onDrawerClosed(View view) {
getActionBar().setTitle(R.string.hello_world);
}
public void onDrawerOpened(View drawerView) {
getActionBar().setTitle(R.string.hello_world);
}
};
drawerLayout.setDrawerListener(drawerToggle);
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
layers = getResources().getStringArray(R.array.planets_array);
drawerList = (ListView) findViewById(R.id.left_drawer);
drawerList.setAdapter(new ArrayAdapter<String>(this,
R.layout.drawer_list_item, android.R.id.text1, layers));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
e.printStackTrace();
e.printStackTrace();
}
}
TestActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
initDrawer();
}