Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JazzyViewPager FragmentStatePagerAdapter #46

Open
creampuffs13 opened this issue May 17, 2014 · 2 comments
Open

JazzyViewPager FragmentStatePagerAdapter #46

creampuffs13 opened this issue May 17, 2014 · 2 comments

Comments

@creampuffs13
Copy link

The problem is that the transitions wont work but all over the app is working fine. It's just the transition effects that aren't working. I've already tried all of them but no luck. There are no errors in the codes too I don't know what I've done wrong so please help. This also my first app so please be kind. :)
I didn't include the instantiateitem on pageradapter because if I do there will be a nullpointerexception. :/
Main Activity:

public class MainActivity extends FragmentActivity {

//private static FragmentAdapter mAdapter;
private JazzyViewPager mJazzy;


  @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    setupJazziness(TransitionEffect.CubeIn);

}

  @Override
public boolean onCreateOptionsMenu(Menu menu) {
    menu.add("Toggle Fade");
    String[] effects = this.getResources().getStringArray(R.array.jazzy_effects);
    for (String effect : effects)
        menu.add(effect);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getTitle().toString().equals("Toggle Fade")) {
        mJazzy.setFadeEnabled(!mJazzy.getFadeEnabled());
    } else {
        TransitionEffect effect = TransitionEffect.valueOf(item.getTitle().toString());
        setupJazziness(effect);
    }
    return true;
}

  private void setupJazziness(TransitionEffect effect) {
      mJazzy = (JazzyViewPager) findViewById(R.id.jazzy_pager);
      mJazzy.setTransitionEffect(effect);
      mJazzy.setAdapter(new FragmentAdapter(getSupportFragmentManager()));
      mJazzy.setPageMargin(30);
  }   

}

Fragment Adapter:
public class FragmentAdapter extends FragmentStatePagerAdapter{

public FragmentAdapter(FragmentManager fm) {
    super(fm);
    // TODO Auto-generated constructor stub
}   

@Override
public Fragment getItem(int position) 
{
    // TODO Auto-generated method stub
    Fragment fragment = new Fragment1();
    switch(position){
    case 0:
        fragment = new Fragment1();
        break;
    case 1:
        fragment = new Fragment2();
        break;
    case 2:
        fragment = new Fragment3();
        break;
    }
    return fragment;
}


@Override
public int getCount() {
    // TODO Auto-generated method stub
    return 3;
}

@Override
public boolean isViewFromObject(View view, Object object) {
    if(object != null){
        return ((Fragment)object).getView() == view;
    }else{
        return false;
    }
}

}

Fragment1:
public class Fragment1 extends Fragment {

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
    View v = inflater.inflate(R.layout.fragment1_layout, null);
    return v;
}    

}

activity_main xml:
<com.jfeinstein.jazzyviewpager.JazzyViewPager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:app1="http://schemas.android.com/apk/res/com.eight.yamjay"
android:id="@+id/jazzy_pager"
app1:style="cubeout"
android:layout_width="match_parent"
android:layout_height="match_parent" />

@dusunboy
Copy link

Just add in FragmentStatePagerAdapter, it will work well

 @Override
        public Object instantiateItem(ViewGroup container, int position) {
            Object obj = super.instantiateItem(container, position);
            mJazzy.setObjectForPosition(obj, position);
            return obj;
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            if(object != null){
                return ((Fragment)object).getView() == view;
            }else{
                return false;
            }
        }

@KickoutByDream
Copy link

Brilliant!You are my Captain!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants