view pager加载下一个片段的数据

时间:2018-02-06 12:24:22

标签: android android-viewpager

ViewPager在滑动或更改标签时加载下一个片段的数据。

我在视图寻呼机中使用相同的片段,并根据视图寻呼机位置替换片段的数据。

以下是设置适配器以查看寻呼机的代码

    Adapter adapter = new Adapter(getSupportFragmentManager());

    ImageListFragment fragment = new ImageListFragment();
    Bundle bundle = new Bundle();
    bundle.putInt("type", 1);
    fragment.setArguments(bundle);
    adapter.addFragment(fragment, getString(R.string.item_1));

    fragment = new ImageListFragment();
    bundle = new Bundle();
    bundle.putInt("type", 2);
    fragment.setArguments(bundle);
    adapter.addFragment(fragment, getString(R.string.item_2));

    fragment = new ImageListFragment();
    bundle = new Bundle();
    bundle.putInt("type", 3);
    fragment.setArguments(bundle);
    adapter.addFragment(fragment, getString(R.string.item_3));

    fragment = new ImageListFragment();
    bundle = new Bundle();
    bundle.putInt("type", 4);
    fragment.setArguments(bundle);
    adapter.addFragment(fragment, getString(R.string.item_4));

    fragment = new ImageListFragment();
    bundle = new Bundle();
    bundle.putInt("type", 5);
    fragment.setArguments(bundle);
    adapter.addFragment(fragment, getString(R.string.item_5));
    adapter.notifyDataSetChanged();

,适配器代码在

下面
    static class Adapter extends FragmentStatePagerAdapter {
    private final List<Fragment> mFragments = new ArrayList<>();
    private final List<String> mFragmentTitles = new ArrayList<>();

        public Adapter(FragmentManager fm) {
            super(fm);
        }

        public void addFragment(Fragment fragment, String title) {
            mFragments.add(fragment);
            mFragmentTitles.add(title);

        }

        @Override
        public Fragment getItem(int position) {
            return mFragments.get(position);
        }

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

        @Override
        public CharSequence getPageTitle(int position) {
            return mFragmentTitles.get(position);
        }

        @Override
        public int getItemPosition(Object object) {
            return POSITION_NONE;
        }
    }

片段代码在

之下
    public static final String STRING_IMAGE_URI = "ImageUri";
    public static final String STRING_IMAGE_POSITION = "ImagePosition";
    public static MainActivity mActivity;
    public static int type;
    ArrayList <ItemsDetails> itemsDetailsArrayList =new ArrayList<>();
    RecyclerView rv;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mActivity = (MainActivity) getActivity();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        rv = (RecyclerView) inflater.inflate(R.layout.layout_recylerview_list, container, false);
       setupRecyclerView();
        return rv;
    }

    private void setupRecyclerView() {

        if (ImageListFragment.this.getArguments().getInt("type") == 1){
            type =1;
            Log.e("ImageListFragment", "1 - fragment - offer");
            itemsDetailsArrayList.clear();
            ImageUrlUtils.setItemList();
            itemsDetailsArrayList= ImageUrlUtils.getItemsList();
            setAdapter(rv, itemsDetailsArrayList);
        }else if (ImageListFragment.this.getArguments().getInt("type") == 2){
            type =2;
            Log.e("ImageListFragment", "2 - fragment - Electronics");
            itemsDetailsArrayList.clear();
            ImageUrlUtils.setElectronicsUrlsDetails();
            itemsDetailsArrayList= ImageUrlUtils.getItemsList();
            setAdapter(rv, itemsDetailsArrayList);
        }else if (ImageListFragment.this.getArguments().getInt("type") == 3){
            type =3;
            Log.e("ImageListFragment", "3 - fragment - Lifestyle");
            itemsDetailsArrayList.clear();
            ImageUrlUtils.setLifeStyleUrls();
            itemsDetailsArrayList= ImageUrlUtils.getItemsList();
            setAdapter(rv, itemsDetailsArrayList);

        }else if (ImageListFragment.this.getArguments().getInt("type") == 4){
            type =4;
            Log.e("ImageListFragment", "4 - fragment - Home Appliances");
            itemsDetailsArrayList.clear();
            ImageUrlUtils.setHomeApplianceUrls();
            itemsDetailsArrayList= ImageUrlUtils.getItemsList();
            setAdapter(rv, itemsDetailsArrayList);
        }else if (ImageListFragment.this.getArguments().getInt("type") == 5){
            type =5 ;
            Log.e("ImageListFragment", "5 - fragment - Books");
            itemsDetailsArrayList.clear();
            ImageUrlUtils.setItemList();
            itemsDetailsArrayList= ImageUrlUtils.getItemsList();
            setAdapter(rv, itemsDetailsArrayList);
        }else {
            type =6;
            Log.e("ImageListFragment", "6 - fragment - more");
            itemsDetailsArrayList.clear();
            ImageUrlUtils.setItemList();
            itemsDetailsArrayList= ImageUrlUtils.getItemsList();
            setAdapter(rv, itemsDetailsArrayList);
        }
    }

       private void setAdapter(RecyclerView rv, ArrayList <ItemsDetails> itemsDetailsArrayList)
    {
        Log.e("ImageListFragment", +type +" itemsDetailsArrayList - "+itemsDetailsArrayList.size());
        StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
        SimpleStringRecyclerViewAdapter simpleStringRecyclerViewAdapter = new SimpleStringRecyclerViewAdapter(mActivity, itemsDetailsArrayList);
        rv.setLayoutManager(layoutManager);
        rv.setAdapter(simpleStringRecyclerViewAdapter);
    }

现在我面临第一个片段加载数据第二个片段的问题。 例如,如果我在第n个片段上显示第n + 1个片段的数据。

,ImageUrlUtils类位于

之下
    public class ImageUrlUtils {
    static ArrayList<String> wishlistImageUri = new ArrayList<>();
    static ArrayList<ItemsDetails> cartListImageUri = new ArrayList<>();

    static ArrayList<ItemsDetails> itemsDetails = new ArrayList<>();
     static ArrayList<ItemsDetails> wishlistedItemsDetails = new ArrayList<>();

public static ArrayList<ItemsDetails> getItemsList()
{
    return itemsDetails;
}
public static void setItemList()
{
    itemsDetails.clear();
    String[] strings = getOffersUrls();

    for (int i =0; i<strings.length; i++)
    {
        ItemsDetails details = new ItemsDetails();
        details.setItemId("food__00"+i);
        details.setItemName("Food Name");
        details.setItemDesc("Offer Desc Offer Desc Offer Desc Offer Desc Offer Desc Food Desc Food Desc");
        details.setItemFullPlatePrice((i+1)*100);
        details.setItemHalfPlateSize((i+1)*100/2);
        details.setDefaultPlateSize(0);
        ArrayList arrayList = new ArrayList();
        for (int j =0 ; j< 5; j++)
        {
          arrayList.add("Point "+j);
        }
        details.setItemsDetails(arrayList);
        details.setImgUrl(strings[i]);
        details.setWishlisted(false);
        details.setQuatity(0);
        itemsDetails.add(details);
    }
}

public static void setElectronicsUrlsDetails()
{
     itemsDetails.clear();
    String[] strings = getElectronicsUrls();

    for (int i =0; i<strings.length; i++)
    {
        ItemsDetails details = new ItemsDetails();
        details.setItemId("food__00"+i);
        details.setItemName("Food Name");
        details.setItemDesc("Breakfast Desc Breakfast Desc Breakfast Desc Food Desc Food Desc Food Desc Food Desc");
        details.setItemFullPlatePrice((i+1)*100);
        details.setItemHalfPlateSize((i+1)*100/2);
        details.setDefaultPlateSize(0);
        ArrayList arrayList = new ArrayList();
        for (int j =0 ; j< 5; j++)
        {
            arrayList.add("Point "+j);
        }
        details.setItemsDetails(arrayList);
        details.setImgUrl(strings[i]);
        details.setWishlisted(false);
        details.setQuatity(0);
        itemsDetails.add(details);
    }
}

public static void setLifeStyleUrls()
{
    itemsDetails.clear();
    String[] strings = getLifeStyleUrls();

    for (int i =0; i<strings.length; i++)
    {
        ItemsDetails details = new ItemsDetails();
        details.setItemId("food__00"+i);
        details.setItemName("Food Name");
        details.setItemDesc("Lunch Desc Lunch Desc Lunch Desc Lunch Desc Food Desc Food Desc Food Desc");
        details.setItemFullPlatePrice((i+1)*100);
        details.setItemHalfPlateSize((i+1)*100/2);
        details.setDefaultPlateSize(0);
        ArrayList arrayList = new ArrayList();
        for (int j =0 ; j< 5; j++)
        {
            arrayList.add("Point "+j);
        }
        details.setItemsDetails(arrayList);
        details.setImgUrl(strings[i]);
        details.setWishlisted(false);
        details.setQuatity(0);
        itemsDetails.add(details);
    }
}

public static void setHomeApplianceUrls()
{
    itemsDetails.clear();
    String[] strings = getHomeApplianceUrls();

    for (int i =0; i<strings.length; i++)
    {
        ItemsDetails details = new ItemsDetails();
        details.setItemId("food__00"+i);
        details.setItemName("Food Name");
        details.setItemDesc("Dinner Desc Dinner Desc Dinner Desc Food Desc Food Desc Food Desc Food Desc");
        details.setItemFullPlatePrice((i+1)*100);
        details.setItemHalfPlateSize((i+1)*100/2);
        details.setDefaultPlateSize(0);
        ArrayList arrayList = new ArrayList();
        for (int j =0 ; j< 5; j++)
        {
            arrayList.add("Point "+j);
        }
        details.setItemsDetails(arrayList);
        details.setImgUrl(strings[i]);
        details.setWishlisted(false);
        details.setQuatity(0);
        itemsDetails.add(details);
    }
}

public static String[] getImageUrls() {
    String[] urls = new String[] {
            "https://static.pexels.com/photos/5854/sea-woman-legs-water-medium.jpg",
            "https://static.pexels.com/photos/6245/kitchen-cooking-interior-decor-medium.jpg",
            "https://static.pexels.com/photos/6770/light-road-lights-night-medium.jpg",
            "https://static.pexels.com/photos/6041/nature-grain-moving-cereal-medium.jpg",
            "https://static.pexels.com/photos/7116/mountains-water-trees-lake-medium.jpg",
            "https://static.pexels.com/photos/6601/food-plate-yellow-white-medium.jpg",

            "https://static.pexels.com/photos/7262/clouds-ocean-seagull-medium.jpg",
            "https://static.pexels.com/photos/5968/wood-nature-dark-forest-medium.jpg",

            "https://static.pexels.com/photos/6571/pexels-photo-medium.jpeg",
            "https://static.pexels.com/photos/6740/food-sugar-lighting-milk-medium.jpg",
            "https://static.pexels.com/photos/5659/sky-sunset-clouds-field-medium.jpg",
            "https://static.pexels.com/photos/6945/sunset-summer-golden-hour-paul-filitchkin-medium.jpg",
            "https://static.pexels.com/photos/6151/animal-cute-fur-white-medium.jpg",
            "https://static.pexels.com/photos/5696/coffee-cup-water-glass-medium.jpg",
            "https://static.pexels.com/photos/6789/flowers-petals-gift-flower-medium.jpg",
            "https://static.pexels.com/photos/7202/summer-trees-sunlight-trail-medium.jpg",
            "https://static.pexels.com/photos/7147/night-clouds-summer-trees-medium.jpg",
            "https://static.pexels.com/photos/6342/woman-notebook-working-girl-medium.jpg",
            "https://static.pexels.com/photos/5998/sky-love-people-romantic-medium.jpg",
            "https://static.pexels.com/photos/6872/cold-snow-nature-weather-medium.jpg",
            "https://static.pexels.com/photos/7045/pexels-photo-medium.jpeg",
            "https://static.pexels.com/photos/6923/mountains-fog-green-beauty-medium.jpg",
            "https://static.pexels.com/photos/6946/summer-bicycle-letsride-paul-filitchkin-medium.jpg",
            "https://static.pexels.com/photos/5650/sky-clouds-field-blue-medium.jpg",
            "https://static.pexels.com/photos/6292/blue-pattern-texture-macro-medium.jpg",
            "https://static.pexels.com/photos/6080/grass-lawn-technology-tablet-medium.jpg",
            "https://static.pexels.com/photos/7124/clouds-trees-medium.jpg",
            "https://static.pexels.com/photos/5923/woman-girl-teenager-wine-medium.jpg",
            "https://static.pexels.com/photos/6133/food-polish-cooking-making-medium.jpg",
            "https://static.pexels.com/photos/6224/hands-people-woman-working-medium.jpg",
            "https://static.pexels.com/photos/6414/rucola-young-argula-sproutus-medium.jpg",
            "https://static.pexels.com/photos/6739/art-graffiti-abstract-vintage-medium.jpg",
            "https://static.pexels.com/photos/6703/city-train-metal-public-transportation-medium.jpg",
            "https://static.pexels.com/photos/6851/man-love-woman-kiss-medium.jpg",
            "https://static.pexels.com/photos/6225/black-scissors-medium.jpg",
            "https://static.pexels.com/photos/7185/night-clouds-trees-stars-medium.jpg",
            "https://static.pexels.com/photos/5847/fashion-woman-girl-jacket-medium.jpg",
            "https://static.pexels.com/photos/5542/vintage-railroad-tracks-bw-medium.jpg",
            "https://static.pexels.com/photos/5938/food-salad-healthy-lunch-medium.jpg",
            "https://static.pexels.com/photos/7234/water-clouds-ocean-splash-medium.jpg",
            "https://static.pexels.com/photos/6418/flowers-flower-roses-rose-medium.jpg",
            "https://static.pexels.com/photos/6436/spring-flower-hyacinth-medium.jpg",
            "https://static.pexels.com/photos/6351/smartphone-desk-laptop-technology-medium.jpg",
            "https://static.pexels.com/photos/5618/fish-fried-mint-pepper-medium.jpg",
            "https://static.pexels.com/photos/6874/landscape-nature-water-rocks-medium.jpg",
            "https://static.pexels.com/photos/6918/bridge-fog-san-francisco-lets-get-lost-medium.jpg",
            "https://static.pexels.com/photos/5658/light-sunset-red-flowers-medium.jpg",
            "https://static.pexels.com/photos/6111/smartphone-friends-internet-connection-medium.jpg",
            "https://static.pexels.com/photos/5670/wood-fashion-black-stylish-medium.jpg",
            "https://static.pexels.com/photos/5838/hands-woman-hand-typing-medium.jpg",
            "https://static.pexels.com/photos/7050/sky-clouds-skyline-blue-medium.jpg",
            "https://static.pexels.com/photos/6036/nature-forest-tree-bark-medium.jpg",
            "https://static.pexels.com/photos/5676/art-camera-photography-picture-medium.jpg",
            "https://static.pexels.com/photos/6688/beach-sand-blue-ocean-medium.jpg",
            "https://static.pexels.com/photos/6901/sunset-clouds-golden-hour-lets-get-lost-medium.jpg",
            "https://static.pexels.com/photos/7260/rocks-fire-camping-medium.jpg",
            "https://static.pexels.com/photos/5672/dog-cute-adorable-play-medium.jpg",
            "https://static.pexels.com/photos/7261/rocks-trees-hiking-trail-medium.jpg",
            "https://static.pexels.com/photos/6411/smartphone-girl-typing-phone-medium.jpg",
            "https://static.pexels.com/photos/6412/table-white-home-interior-medium.jpg",
            "https://static.pexels.com/photos/6184/technology-keyboard-desktop-book-medium.jpg",
            "https://static.pexels.com/photos/7295/controller-xbox-gaming-medium.jpg",
            "https://static.pexels.com/photos/6732/city-cars-traffic-lights-medium.jpg",
            "https://static.pexels.com/photos/7160/bird-trees-medium.jpg",
            "https://static.pexels.com/photos/6999/red-hand-summer-berries-medium.jpg",
            "https://static.pexels.com/photos/5787/flowers-meadow-spring-green-medium.jpg",
            "https://static.pexels.com/photos/7136/water-rocks-stream-leaves-medium.jpg",
            "https://static.pexels.com/photos/7291/building-historical-church-religion-medium.jpg",
            "https://static.pexels.com/photos/6696/road-nature-summer-forest-medium.jpg",
            "https://static.pexels.com/photos/7294/garden-medium.jpg",
            "https://static.pexels.com/photos/6948/flight-sky-art-clouds-medium.jpg",
            "https://static.pexels.com/photos/7299/africa-animals-zoo-zebras-medium.jpg",
            "https://static.pexels.com/photos/6345/dark-brown-milk-candy-medium.jpg",
            "https://static.pexels.com/photos/7288/animal-dog-pet-park-medium.jpg",
            "https://static.pexels.com/photos/5863/nature-plant-leaf-fruits-medium.jpg",
            "https://static.pexels.com/photos/6625/pexels-photo-medium.jpeg",
            "https://static.pexels.com/photos/6708/stairs-people-sitting-architecture-medium.jpg",
            "https://static.pexels.com/photos/6429/smartphone-technology-music-white-medium.jpg",
            "https://static.pexels.com/photos/6574/pexels-photo-medium.jpeg",
            "https://static.pexels.com/photos/7287/grass-lawn-meadow-medium.jpg",
            "https://static.pexels.com/photos/6100/man-hands-holidays-looking-medium.jpg",
            "https://static.pexels.com/photos/6100/man-hands-holidays-looking-medium.jpg",
            "https://static.pexels.com/photos/6877/dog-pet-fur-brown-medium.jpg",
            "https://static.pexels.com/photos/6790/light-road-nature-iphone-medium.jpg",
            "https://static.pexels.com/photos/7077/man-people-office-writing-medium.jpg",
            "https://static.pexels.com/photos/6889/light-mountains-sunrise-california-medium.jpg",
            "https://static.pexels.com/photos/7274/leaf-fall-foliage-medium.jpg",
            "https://static.pexels.com/photos/7285/flowers-garden-medium.jpg",
            "https://static.pexels.com/photos/6821/light-sky-beach-sand-medium.jpg",
            "https://static.pexels.com/photos/7297/animal-africa-giraffe-medium.jpg",
            "https://static.pexels.com/photos/6154/sea-sky-water-clouds-medium.jpg",
            "https://static.pexels.com/photos/7059/man-people-space-desk-medium.jpg",
            "https://static.pexels.com/photos/6666/coffee-cup-mug-apple-medium.jpg",
            "https://static.pexels.com/photos/5949/food-nature-autumn-nuts-medium.jpg",
            "https://static.pexels.com/photos/7064/man-notes-macbook-computer-medium.jpg",
            "https://static.pexels.com/photos/5743/beach-sand-legs-shoes-medium.jpg",
            "https://static.pexels.com/photos/6355/desk-laptop-working-technology-medium.jpg",
            "https://static.pexels.com/photos/5844/sea-water-boats-boat-medium.jpg",
            "https://static.pexels.com/photos/5541/city-night-building-house-medium.jpg",
            "https://static.pexels.com/photos/7017/food-peppers-kitchen-yum-medium.jpg",
            "https://static.pexels.com/photos/5725/grey-luxury-carpet-silver-medium.jpg",
            "https://static.pexels.com/photos/6932/italian-vintage-old-beautiful-medium.jpg",
            "https://static.pexels.com/photos/7093/coffee-desk-notes-workspace-medium.jpg",
    };
    return urls;
}

public static String[] getOffersUrls() {
    String[] urls = new String[]{
            "https://static.pexels.com/photos/1543/landscape-nature-man-person-medium.jpg",
            "https://static.pexels.com/photos/211048/pexels-photo-211048-medium.jpeg",
            "https://static.pexels.com/photos/1778/numbers-time-watch-white-medium.jpg",
            "https://static.pexels.com/photos/111147/pexels-photo-111147-medium.jpeg",
            "https://static.pexels.com/photos/2713/wall-home-deer-medium.jpg",
            "https://static.pexels.com/photos/168575/pexels-photo-168575-medium.jpeg",
            "https://static.pexels.com/photos/213384/pexels-photo-213384-medium.jpeg",
            "https://static.pexels.com/photos/67442/pexels-photo-67442-medium.jpeg",
            "https://static.pexels.com/photos/159494/book-glasses-read-study-159494-medium.jpeg",
            "https://static.pexels.com/photos/1543/landscape-nature-man-person-medium.jpg",
            "https://static.pexels.com/photos/211048/pexels-photo-211048-medium.jpeg",
            "https://static.pexels.com/photos/2713/wall-home-deer-medium.jpg",
            "https://static.pexels.com/photos/177143/pexels-photo-177143-medium.jpeg",
            "https://static.pexels.com/photos/106936/pexels-photo-106936-medium.jpeg"
    };
    return urls;
}

public static String[] getHomeApplianceUrls() {
    String[] urls = new String[]{
            "https://static.pexels.com/photos/1778/numbers-time-watch-white-medium.jpg",
            "https://static.pexels.com/photos/189293/pexels-photo-189293-medium.jpeg",
            "https://static.pexels.com/photos/4703/inside-apartment-design-home-medium.jpg",
            "https://static.pexels.com/photos/133919/pexels-photo-133919-medium.jpeg",
            "https://static.pexels.com/photos/111147/pexels-photo-111147-medium.jpeg",
            "https://static.pexels.com/photos/2713/wall-home-deer-medium.jpg",
            "https://static.pexels.com/photos/177143/pexels-photo-177143-medium.jpeg",
            "https://static.pexels.com/photos/106936/pexels-photo-106936-medium.jpeg",
            "https://static.pexels.com/photos/1778/numbers-time-watch-white-medium.jpg",
            "https://static.pexels.com/photos/189293/pexels-photo-189293-medium.jpeg",
            "https://static.pexels.com/photos/4703/inside-apartment-design-home-medium.jpg",
            "https://static.pexels.com/photos/133919/pexels-photo-133919-medium.jpeg",
            "https://static.pexels.com/photos/111147/pexels-photo-111147-medium.jpeg",
            "https://static.pexels.com/photos/2713/wall-home-deer-medium.jpg",
            "https://static.pexels.com/photos/177143/pexels-photo-177143-medium.jpeg",
            "https://static.pexels.com/photos/106936/pexels-photo-106936-medium.jpeg"
    };
    return urls;
}

public static String[] getElectronicsUrls() {
    String[] urls = new String[]{
            "https://static.pexels.com/photos/204611/pexels-photo-204611-medium.jpeg",
            "https://static.pexels.com/photos/214487/pexels-photo-214487-medium.jpeg",
            "https://static.pexels.com/photos/168575/pexels-photo-168575-medium.jpeg",
            "https://static.pexels.com/photos/213384/pexels-photo-213384-medium.jpeg",
            "https://static.pexels.com/photos/114907/pexels-photo-114907-medium.jpeg",
            "https://static.pexels.com/photos/185030/pexels-photo-185030-medium.jpeg",
            "https://static.pexels.com/photos/133579/pexels-photo-133579-medium.jpeg",
            "https://static.pexels.com/photos/51383/photo-camera-subject-photographer-51383-medium.jpeg",
            "https://static.pexels.com/photos/205926/pexels-photo-205926-medium.jpeg",
            "https://static.pexels.com/photos/2396/light-glass-lamp-idea-medium.jpg",
            "https://static.pexels.com/photos/1854/person-woman-hand-relaxing-medium.jpg",
            "https://static.pexels.com/photos/204611/pexels-photo-204611-medium.jpeg",
            "https://static.pexels.com/photos/214487/pexels-photo-214487-medium.jpeg",
            "https://static.pexels.com/photos/168575/pexels-photo-168575-medium.jpeg",
            "https://static.pexels.com/photos/213384/pexels-photo-213384-medium.jpeg",
            "https://static.pexels.com/photos/114907/pexels-photo-114907-medium.jpeg"
    };
    return urls;
}

public static String[] getLifeStyleUrls() {
    String[] urls = new String[]{
            "https://static.pexels.com/photos/169047/pexels-photo-169047-medium.jpeg",
            "https://static.pexels.com/photos/160826/girl-dress-bounce-nature-160826-medium.jpeg",
            "https://static.pexels.com/photos/1702/bow-tie-businessman-fashion-man-medium.jpg",
            "https://static.pexels.com/photos/35188/child-childrens-baby-children-s-medium.jpg",
            "https://static.pexels.com/photos/70845/girl-model-pretty-portrait-70845-medium.jpeg",
            "https://static.pexels.com/photos/26378/pexels-photo-26378-medium.jpg",
            "https://static.pexels.com/photos/193355/pexels-photo-193355-medium.jpeg",
            "https://static.pexels.com/photos/1543/landscape-nature-man-person-medium.jpg",
            "https://static.pexels.com/photos/211048/pexels-photo-211048-medium.jpeg",
            "https://static.pexels.com/photos/189857/pexels-photo-189857-medium.jpeg",
            "https://static.pexels.com/photos/157948/model-modelling-attractive-fashion-157948-medium.jpeg",
            "https://static.pexels.com/photos/33608/dog-ice-woman-purple-medium.jpg",
            "https://static.pexels.com/photos/157940/hair-bracelet-beautiful-beauty-157940-medium.jpeg",
            "https://static.pexels.com/photos/35188/child-childrens-baby-children-s-medium.jpg",
            "https://static.pexels.com/photos/70845/girl-model-pretty-portrait-70845-medium.jpeg",
            "https://static.pexels.com/photos/26378/pexels-photo-26378-medium.jpg",
            "https://static.pexels.com/photos/193355/pexels-photo-193355-medium.jpeg",
    };
    return urls;
}

public void addWishlistImageUri(String wishlistImageUri) {
    this.wishlistImageUri.add(0,wishlistImageUri);
}

public static void addWishlistImageUri(ItemsDetails wishlistImageUri) {
    wishlistImageUri.setQuatity(1);
    wishlistedItemsDetails.add(wishlistImageUri);
}

public static void removeWishlistImageUri(String foofId) {

    for (int i=0; i<wishlistedItemsDetails.size() ;i++)
    {
        ItemsDetails itemsDetails = wishlistedItemsDetails.get(i);
        if (itemsDetails.getItemId().equals(foofId))
        {
            wishlistedItemsDetails.remove(i);
            break;
        }
    }
}

public static ArrayList<ItemsDetails> getWishlistImageUri(){
    return wishlistedItemsDetails;
}

public static void updateItemsDeatils(String itemId){

    for (int i =0; i< itemsDetails.size(); i++)
    {
        ItemsDetails details = itemsDetails.get(i);
        if (details.getItemId().equals(itemId)) {
            details.setQuatity(0);
            details.setWishlisted(false);
            break;
        }

}

public void addCartListImageUri(ItemsDetails wishlistImageUri, int default_plate_postion) {

  if (!checkCart(wishlistImageUri)) {
      wishlistImageUri.setQuatity(1);
      wishlistImageUri.setDefaultPlateSize(default_plate_postion);
      this.cartListImageUri.add(wishlistImageUri);
  }
}

public static boolean checkCart(ItemsDetails wishlistImageUri)
{
    boolean value = false;
    for (int i = 0; i< cartListImageUri.size() ; i++)
    {
        ItemsDetails itemsDetails = cartListImageUri.get(i);
        if (itemsDetails.getItemId().equals(wishlistImageUri.getItemId()))
        {
            value = true;
        }
        else value = false;
    }
    return value;
}
public static void removeCartListImageUri(String foodId) {
    for (int i=0;i<cartListImageUri.size();i++)
    {
        ItemsDetails itemsDetails = cartListImageUri.get(i);
        if (itemsDetails.getItemId().equals(foodId))
        {
            cartListImageUri.remove(i);
            break;
        }
    }
}
public ArrayList<ItemsDetails> getCartListImageUri(){ return this.cartListImageUri; }

}

1 个答案:

答案 0 :(得分:0)

ViewPager打算以这种方式工作以避免在从一个片段切换到另一个片段时动画滞后,它将在您的可见片段旁边加载至少一个额外片段,以确保有可以滑动的范围。

因为,虽然滑动视图寻呼机能够同时显示两个片段因此总是加载一个片段,没有两个页面的视图寻呼机是无用的。