0

I'd like to know if it is possible to define one element, in this case a drawer, in one xml file and then call it on all the layouts, so I don't have to manually define the drawer each time, reducing the chance of errors and the effort needed to fix it.

EDIT:

So this is the list view, that is the drawer:

<ListView
        android:id="@id/navList"
        android:layout_width="180dp"
        android:layout_height="match_parent"
        android:layout_gravity="left|start"
        android:background="#ffeeeeee"/>

And this is the java code so I can put what i want on the list:

    private void addDrawerItems() {

    Resources res = getResources();
    String[] osArray = res.getStringArray(R.array.DrawerButtons);
    mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, osArray);
    mDrawerList.setAdapter(mAdapter);
}

    mDrawerList = (ListView)findViewById(R.id.navList);

I'm asking what might look like a stupid question, or an easy one, but I really don't know, I only started fiddling with Android Development yesterday.

Zé Pedro
  • 53
  • 6
  • You can use fragments – Codelord Apr 18 '15 at 10:56
  • Yes, you can inflate an XML layout multiple times and get different views. Please post the relevant parts of the code that do you have so far and maybe someone can help you. – dhke Apr 18 '15 at 10:57
  • I think you have to define one parent layout with drawer and container layoyut and try to define BaseActivity with load this parent layout then try to extend BaseActivity to all activity where you required drawer and set activity layout in parent container check out this for idea : http://stackoverflow.com/questions/22652556/creating-base-activity-with-navigation-drawer-in-android. – Haresh Chhelana Apr 18 '15 at 11:05
  • @HareshChhelana Thank you very much, I fully understood it and it feels like a very good option to deal with my problem. I'll get working on it and will report back if I can make it work on my case. Care to write an answer so I can mark this as solved? – Zé Pedro Apr 18 '15 at 11:15
  • @ZéPedro,Sure glad to guide you. – Haresh Chhelana Apr 18 '15 at 11:15

0 Answers0