How to add title in Navigation drawer layout?

wawanopoulos picture wawanopoulos · Jun 5, 2013 · Viewed 23.1k times · Source

[UPDATE]

I solve the problem by adding addHeaderView :

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mTitle = mDrawerTitle = getTitle();
    mPlanetTitles = getResources().getStringArray(R.array.planets_array);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);

    LayoutInflater inflater = getLayoutInflater();
    ViewGroup mTop = (ViewGroup)inflater.inflate(R.layout.header_listview_menu, mDrawerList, false);
    mDrawerList.addHeaderView(mTop, null, false);

================================

My question is so simple !

I would like to how to add a title in a navigation drawer ?

I already created my navigation drawer with listview (icon+text) for each item.

Thanks a lot,

enter image description here

Answer

CommonsWare picture CommonsWare · Jun 5, 2013

You would do that the same way as you would add headings in any other ListView, by teaching your ListAdapter to return heading rows as well as detail rows. At the low level, this involves overriding methods like getViewTypeCount() and getItemViewType() in your ListAdapter, plus having getView() know the difference between the row types. Or, use an existing high-level implementation like https://github.com/emilsjolander/StickyListHeaders or http://code.google.com/p/android-amazing-listview/ or any of the others found when searching for android listview headers.