title: Adapt chrisbanes ActionBar-PullToRefresh to Fragments(NavigationDrawer)
body: <p>Okay here is my problem:</p>
  
  <p>I want to implement Chrisbanes ActionBar-PullToRefresh library with fragments to be able to use it with Navigationdrawer.</p>
  
  <blockquote>
    <p><a href="https://github.com/chrisbanes/ActionBar-PullToRefresh#fragments" rel="nofollow noreferrer">https://github.com/chrisbanes/ActionBar-PullToRefresh#fragments</a></p>
  </blockquote>
  
  <p>.</p>
  
  <p>Chrisbanes says this for the use with fragments:</p>
  
  <blockquote>
    <p>One thing to note is that the PullToRefreshAttacher needs to be
    created in the onCreate() phase of the Activity. If you plan on using
    this library with Fragments then the best practice is for your
    Activity to create the PullToRefreshAttacher, and then have your
    fragments retrieve it from the Activity.</p>
    
    <p>An example is provided in the Fragment &amp; Tabs sample.</p>
  </blockquote>
  
  <p>.</p>
  
  <p>.</p>
  
  <p>****Here comes the question:
  I created the PullToRefreshAttacher in my activity but how the hell could I pass the PullToRefreshAttacher to my fragments :S****</p>
  
  <p>I have read much about bundles and getArguments() with putSerializable and Parcelable :</p>
  
  <blockquote>
    <p><a href="https://stackoverflow.com/questions/9931993/passing-an-object-from-an-activity-to-a-fragment">Passing an Object from an Activity to a Fragment</a></p>
  </blockquote>
  
  <p>and I also read this article in which sth. like this <code>((MyActivity )  getActivity()).getClassX() ;</code> is used.</p>
  
  <blockquote>
    <p><a href="https://stackoverflow.com/questions/12070215/call-activity-method-from-fragment">Call Activity Method From Fragment</a></p>
  </blockquote>
  
  <p>But nothing I really understood/worked. :(</p>
  
  <p>.</p>
  
  <p>.</p>
  
  <p>Here are the NavigationActivity and one example fragment.I have to say that I am new to android/Java :)</p>
  
  <pre><code>    final String[] menuEntries = {"Start","Datum","Website","Kunden"};
  final String[] fragments = {
          "com.blabla.MainFragment",
          "com.blabla.OneFragment",
          "com.blabla.TwoFragment",
          "com.blabla.KundenFragment",
  };
  
  private ActionBarDrawerToggle drawerToggle;
  private DrawerLayout drawerAdapter;
  private ListView navListAdapter;
  
  
  
  
  private PullToRefreshAttacher mPullToRefreshAttacher;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
  
      setContentView(R.layout.navigation_layout);
  
      mPullToRefreshAttacher = PullToRefreshAttacher.get(this);
  
  
  
      ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(getActionBar().getThemedContext(), android.R.layout.simple_list_item_1, menuEntries);
  
      final DrawerLayout drawer = (DrawerLayout)findViewById(R.id.refresh_navwiev);
      final ListView navList = (ListView) findViewById(R.id.drawerMenu);
  
      drawerAdapter=drawer;
      navListAdapter=navList;
  
      getActionBar().setDisplayHomeAsUpEnabled(true);
      getActionBar().setHomeButtonEnabled(true);
  
  
     drawerToggle = new ActionBarDrawerToggle(
              this, 
              drawer,
              R.drawable.navicon,
              R.string.drawer_open,
              R.string.drawer_close
      ) {
  
          /** Called when a drawer has settled in a completely closed state. */
          public void onDrawerClosed(View view) {
  
          }
  
          /** Called when a drawer has settled in a completely open state. */
          public void onDrawerOpened(View drawerView) {
  
          }
  
  
      };
  
      drawer.setDrawerListener(drawerToggle);
  
  
  
      navList.setAdapter(adapter);
      navList.setOnItemClickListener(new OnItemClickListener(){
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view, final int pos,long id){
              drawer.setDrawerListener( new DrawerLayout.SimpleDrawerListener(){
                  @Override
                  public void onDrawerClosed(View drawerView){
                      super.onDrawerClosed(drawerView);
                      //Runs On completly Closed
                  }
              });
  
              //Runs Onclick if not same fragment
              if(getActionBar().getTitle()!= menuEntries[pos])
              {
  
              Bundle bundle=new Bundle();
              bundle.putString("message", "From Activity");
  
              //Fragment zusammenbauen
              Fragment myFragment=new Fragment();
              myFragment = Fragment.instantiate(NavigationActivity.this, fragments[pos]);
              myFragment.setArguments(bundle);
  
  
                  FragmentTransaction tx = getSupportFragmentManager().beginTransaction();
                  tx.setCustomAnimations(R.anim.fragmentfadein, R.anim.fragmentfadeout);
                  tx.replace(R.id.navigationScreen, myFragment);
  
                  tx.commit();
                  getActionBar().setTitle(menuEntries[pos]);
                  drawer.closeDrawer(navList);
              }
          }
      });
  
      Bundle bundle=new Bundle();
   //     bundle.putInt(PullToRefreshAttacher., position);
  
      //Fragment zusammenbauen
      Fragment myFragment=new Fragment();
      myFragment = Fragment.instantiate(NavigationActivity.this, fragments[0]);
      myFragment.setArguments(bundle);
  
  
          FragmentTransaction tx = getSupportFragmentManager().beginTransaction();
          tx.setCustomAnimations(R.anim.fragmentfadein, R.anim.fragmentfadeout);
          tx.replace(R.id.navigationScreen, myFragment);
  
          tx.commit();
  
  }
  
  public boolean onKeyUp(int keyCode, KeyEvent event) {
      if (keyCode == KeyEvent.KEYCODE_MENU) {
  
          Log.i("FlosTemplate", "Menu Taste Gedrückt");
  
              if(drawerAdapter.isDrawerOpen(navListAdapter))
              {
              drawerAdapter.closeDrawer(navListAdapter);
              }
              else
              {
              drawerAdapter.openDrawer(navListAdapter);
              }
  
          return true;
      }
      return super.onKeyUp(keyCode, event);
  }
  
  @Override
  protected void onPostCreate(Bundle savedInstanceState) {
      super.onPostCreate(savedInstanceState);
      drawerToggle.syncState();
  }
  
  @Override
  public void onConfigurationChanged(Configuration newConfig) {
      super.onConfigurationChanged(newConfig);
      drawerToggle.onConfigurationChanged(newConfig);
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      if (drawerToggle.onOptionsItemSelected(item)) {
          return true;
      }
  
      return super.onOptionsItemSelected(item);
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      getMenuInflater().inflate(R.menu.main, menu);
      return true;
  }
  
  
  }
  </code></pre>
  
  <p>And a fragment</p>
  
  <pre><code>public class MainFragment extends Fragment  {
  
  public static Fragment newInstance(Context context) {
      MainFragment f = new MainFragment();
      return f;
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
      View rootView = inflater.inflate(R.layout.fragment_main, container, false);
  
  
  
      return rootView;
  }
  
  }
  </code></pre>
  
  <p>It would be very kind if somebody could help me ,i am  stuck at this point for days :) </p>
  
  <p>P.S. sorry for the probably bad language , i am not a native speaker ;)</p>