I have followed a bunch of examples for implementing the same NavigationDrawer in all activities so far no success. I have 2 issues:
1. I Have defined a BaseActivity and Override its setContentView. BUT in setContentView I don't seem to be able to access the ListView containing my NavDrawer items. (drawerListView returns null)
- How am I supposed to reuse the code for my NavDrawer? I could not find a good example here. I don't like to add a DrawerLayout, FrameLayout and ListView to all my Fragment layout xmls.
What am I supposed to do? any good and clear example is highly appreciated.
The code for my BaseActivity
public class BaseActivity extends ActionBarActivity implements OnItemClickListener
{
private DrawerLayout drawerLayout;
private String[] properties;
private ListView drawerListView;
protected DrawerLayout fullLayout;
protected FrameLayout actContent;
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
Intent intent2=new Intent(BaseActivity.this, ActivitySearchForSale.class);
startActivity(intent2);
}
@Override
public void setContentView(int layoutResID) {
fullLayout= (DrawerLayout) getLayoutInflater().inflate(layoutResID, null); // Your base layout here
actContent= (FrameLayout) fullLayout.findViewById(R.id.drawer_layout);
drawerListView = (ListView) findViewById(R.id.drawerList);
properties = getResources().getStringArray(R.array.propertyTypeArray);
drawerListView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, properties));
drawerListView.setOnItemClickListener((OnItemClickListener) this);
getLayoutInflater().inflate(layoutResID, actContent, true); // Setting the content of layout your provided to the act_content frame
super.setContentView(fullLayout);
}
The code for my activity_main.xml i which I have defined the DrawerLayout and I don't know how to include this in my other fragment layouts.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/mainContent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
style="@style/StyleForSimpleTextView"
android:text="zzzzz"
/>
</FrameLayout>
<!-- Use any Views you like -->
<ListView
android:id="@+id/drawerList"
android:layout_width="240dp"
android:layout_height="match_parent"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#ffffff"
android:layout_gravity="left"
/>
</android.support.v4.widget.DrawerLayout>
0 comments:
Post a Comment