andreich
@andreich

Почему ViewPager с фрагментами перелистывает с задержкой?

Добрый день!
Использую вот такой вот адаптер для ViewPager. Элементов в customObjectList порядка 100 штук.
Я не понимаю, как убрать задержку при пролистывании. Google ничем не смог помочь, везде используются пример от гугла
Собственно вопрос состоит в том, как убрать задержку?
public class CustomObjectPagerAdapter extends FragmentPagerAdapter
{
    private final List<CustomObject> customObjectList;
    private SparseArray<String> mFragmentTags;
    private FragmentManager mFragmentManager;

    public CustomObjectPagerAdapter(final FragmentManager fm, final List<CustomObject> customObjectList)
    {
        super(fm);
        this.customObjectList = customObjectList;
        mFragmentTags = new SparseArray<String>();
        mFragmentManager = fm;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position)
    {
        final Object obj = super.instantiateItem(container, position);
        if (obj instanceof Fragment)
        {            
            final Fragment f = (Fragment) obj;
            final String tag = f.getTag();
            mFragmentTags.put(position, tag);
        }
        return obj;
    }

    @Override
    public Fragment getItem(final int i)
    {
        final String tag = mFragmentTags.get(i);
        final CustomObjectFragment fragment;

        if (tag == null)
            fragment = CustomObjectFragment.newInstance(customObjectList.get(i));
        else
        {
            fragment = (CustomObjectFragment)mFragmentManager.findFragmentByTag(tag);
            fragment.updateCustomObject(customObjectList.get(i));

        }
        return fragment;
    }

    @Override
    public int getCount()
    {
        return customObjectList.size();
    }
}


UPD: если использовать пример гугловский, то задержка тоже есть. Собственно с него все и начиналось

UPD2: Код фрагмента
public class CustomObjectFragment extends Fragment 
{
    private CustomObject customObject;
    private View rootView;  
    


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup contaner, Bundle saveInstanceState)
    {
        rootView =  inflater.inflate(R.layout.fragment_customObject, contaner, false);       
        textView = (TextView) rootView.findViewById(R.id.customObjectText);        
        if (saveInstanceState == null)
            saveInstanceState = getArguments();
        updateCustomObject(saveInstanceState);
        return rootView;
    }

    @Overrid
    public void onActivityCreated(Bundle saveInstanceState)
    {
        super.onActivityCreated(saveInstanceState);
    }

    public void updateCustomObject(final Bundle bundle)
    {
        if (bundle != null)
        {
            final CustomObject customObject = bundle.getParcelable("CustomObject");
            updateCustomObject(customObject);
        }
        else
            clear();

    }


    public void updateCustomObject(final CustomObject customObject)
    {        
        textView.setText("nfcrdkfhgkdhfgdgjdhlghjdlkfj");
    }

    public static CustomObjectFragment newInstance(final CustomObject customObject)
    {
        final CustomObjectFragment fragment = new CustomObjectFragment();
        final Bundle args = new Bundle();
        args.putParcelable("CustomObject",customObject);
        fragment.setArguments(args);
        return fragment;
    }

}
  • Вопрос задан
  • 3339 просмотров
Решения вопроса 1
andreich
@andreich Автор вопроса
В общем проблема была в Parcelable.
Была медленная упаковка/распаковка.
Ответ написан
Комментировать
Пригласить эксперта
Ответы на вопрос 2
Использовать более мощное железо. Это же Android. Смиритесь.
Ответ написан
@bimeg
Дело не в пагере, а в ваших фрагментах.
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы