title: Android how to use DatePicker in Fragment?
body: <p>I used this method  <a href="http://www.androidhive.info/2015/04/android-getting-started-with-material-design/" rel="nofollow">http://www.androidhive.info/2015/04/android-getting-started-with-material-design/</a>  to implimenting navigation drawer. but date picker is not working in this.</p>
  
  <p><a href="http://i.stack.imgur.com/ikuko.png" rel="nofollow">enter image description here</a>
  MainActivity.java</p>
  
  <pre><code>import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.support.v4.app.FragmentManager;
  import android.support.v4.app.FragmentTransaction;
  import android.support.v4.widget.DrawerLayout;
  import android.support.v7.app.ActionBarActivity;
  import android.support.v7.widget.Toolbar;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.View;
  import android.widget.Toast;
  public class MainActivity extends ActionBarActivity implements FragmentDrawer.FragmentDrawerListener {
  
      private static String TAG = MainActivity.class.getSimpleName();
  
      private Toolbar mToolbar;
      private FragmentDrawer drawerFragment;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          mToolbar = (Toolbar) findViewById(R.id.toolbar);
  
          setSupportActionBar(mToolbar);
          getSupportActionBar().setDisplayShowHomeEnabled(true);
  
          drawerFragment = (FragmentDrawer)
                  getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);
          drawerFragment.setUp(R.id.fragment_navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), mToolbar);
          drawerFragment.setDrawerListener(this);
  
          // display the first navigation drawer view on app launch
          displayView(0);
      }
  
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.menu_main, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          // Handle action bar item clicks here. The action bar will
          // automatically handle clicks on the Home/Up button, so long
          // as you specify a parent activity in AndroidManifest.xml.
          int id = item.getItemId();
  
          //noinspection SimplifiableIfStatement
          if (id == R.id.action_settings) {
              return true;
          }
  
          if(id == R.id.action_search){
              Toast.makeText(getApplicationContext(), "Search action is selected!", Toast.LENGTH_SHORT).show();
              return true;
          }
  
          return super.onOptionsItemSelected(item);
      }
  
      @Override
      public void onDrawerItemSelected(View view, int position) {
              displayView(position);
      }
  
      private void displayView(int position) {
          Fragment fragment = null;
          String title = getString(R.string.app_name);
          switch (position) {
              case 0:
                  fragment = new HomeFragment();
                  title = getString(R.string.title_home);
                  break;
              case 1:
                  fragment = new FriendsFragment();
                  title = getString(R.string.title_friends);
                  break;
              case 2:
                  fragment = new MessagesFragment();
                  title = getString(R.string.title_messages);
                  break;
              default:
                  break;
          }
  
          if (fragment != null) {
              FragmentManager fragmentManager = getSupportFragmentManager();
              FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
              fragmentTransaction.replace(R.id.container_body, fragment);
              fragmentTransaction.commit();
  
              // set the toolbar title
              getSupportActionBar().setTitle(title);
          }
      }
  }
  </code></pre>
  
  <p>HomeFragment.java</p>
  
  <pre><code>import android.app.Activity;
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  
  
  public class HomeFragment extends Fragment {
  
      public HomeFragment() {
          // Required empty public constructor
      }
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          View rootView = inflater.inflate(R.layout.fragment_home, container, false);
  
  
          // Inflate the layout for this fragment
          return rootView;
      }
  
      @Override
      public void onAttach(Activity activity) {
          super.onAttach(activity);
      }
  
      @Override
      public void onDetach() {
          super.onDetach();
      }
  }
  </code></pre>