像 Amazon prime 这样的电影应用程序,我会使用 CategoryItem 显示电影类别。我想用Recycler显示所有类别

问题描述 投票:0回答:3

我把事情搞混了。我遇到的最初错误是这个 MainActivity.java:130: error: incomplete types: List can be conversion to List allCategoryList.add(new AllCategory(1,"VIP Hour", homeCatListItem1)); 当尝试修复它时,事情开始变得混乱。所以我仍然有这个错误

主要活动


import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;


import com.google.android.material.tabs.TabLayout;
import com.kuroniczstudio.splashscreen.adapter.BannerMoviesPagerAdapter;
import com.kuroniczstudio.splashscreen.adapter.MainRecyclerAdapter;
import com.kuroniczstudio.splashscreen.model.AllCategory;
import com.kuroniczstudio.splashscreen.model.BannerMovies;

import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

    public class MainActivity extends AppCompatActivity {

    BannerMoviesPagerAdapter bannerMoviesPagerAdapter;
    TabLayout indicatorTab, categoryTab;
    ViewPager bannerMoviesViewPager;
    List<BannerMovies> homeBannerList;
    List<BannerMovies> vipHourBannerList;
    List<BannerMovies> prophecyBannerList;
    List<BannerMovies> testimonyBannerList;
    Timer sliderTimer;

    MainRecyclerAdapter mainRecyclerAdapter;
    RecyclerView mainRecycler;
    List<AllCategory> allCategoryList;


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

        indicatorTab = findViewById(R.id.tab_indicator);
        categoryTab = findViewById(R.id.tablayout);

        homeBannerList = new ArrayList<>();
        homeBannerList.add(new BannerMovies(1, "Trailer - I cannot give up now!!!", "https://i.pinimg.com/originals/1a/5e/c6/1a5ec63c50513055ac7674ad65c2e1a1.jpg", "https://youtu.be/7w1YKrHW85c"));
        homeBannerList.add(new BannerMovies(2, "Trailer - I must cross the Red Sea", "https://i.pinimg.com/originals/7f/8f/02/7f8f02fdfc2b09de9d01d86395d128b1.jpg", "https://youtu.be/88dHJdCyyBA"));
        homeBannerList.add(new BannerMovies(3, "Trailer - I must be better than my Father", "https://i.pinimg.com/originals/ec/60/46/ec604668771e8916466be6835d2ea588.jpg", "https://youtu.be/GsNrJgLSTAM"));

        vipHourBannerList = new ArrayList<>();
        vipHourBannerList.add(new BannerMovies(1, "I will be better than my father", "https://i.pinimg.com/originals/ec/60/46/ec604668771e8916466be6835d2ea588.jpg", "https://youtu.be/ymIUteex694"));
        vipHourBannerList.add(new BannerMovies(3, "I must cross the Red Sea", "https://i.pinimg.com/originals/7f/8f/02/7f8f02fdfc2b09de9d01d86395d128b1.jpg", "https://youtu.be/Sbbu536E9vA"));
        vipHourBannerList.add(new BannerMovies(4, "My Hair Will Grow Again", "https://img.yts.mx/assets/images/movies/sharkula_2022/medium-cover.jpg", "https://youtu.be/yau5eQH1K_I"));

        prophecyBannerList = new ArrayList<>();
        prophecyBannerList.add(new BannerMovies(2, "Looking for Jackie", "https://img.yts.mx/assets/images/movies/looking_for_jackie_2009/medium-cover.jpg", "https://www.youtube.com/watch?v=ByYWL1SEe-k"));
        prophecyBannerList.add(new BannerMovies(3, "Khuda Haafiz Chapter II", "https://sdmoviespoint.mba/wp-content/uploads/2022/07/Khuda-Haafiz-Chapter-II-Agni-Pariksha-2022-Full-Movie-Download-Free.jpg", "https://www.youtube.com/watch?v=ByYWL1SEe-k"));
        prophecyBannerList.add(new BannerMovies(4, "Sharkula", "https://img.yts.mx/assets/images/movies/sharkula_2022/medium-cover.jpg", "https://youtu.be/6SOEYXZK6Q4"));
        prophecyBannerList.add(new BannerMovies(5, "Looking for Jackie", "https://img.yts.mx/assets/images/movies/looking_for_jackie_2009/medium-cover.jpg", "https://www.youtube.com/watch?v=ByYWL1SEe-k"));

        testimonyBannerList = new ArrayList<>();
        testimonyBannerList.add(new BannerMovies(1, "See how this little boy survived under the water for 2 hours", "https://i.pinimg.com/originals/14/f1/5c/14f15cc3bbc780abdfecafa0f94024e1.jpg", "https://youtu.be/rRFkBLGQIs8"));
        testimonyBannerList.add(new BannerMovies(2, "Testimony Blessing Nsikak Saved from spiritual attack", "https://i.pinimg.com/originals/14/f1/5c/14f15cc3bbc780abdfecafa0f94024e1.jpg", "https://youtu.be/TdYn24MdD1Q"));
        testimonyBannerList.add(new BannerMovies(3, "See how this man got back his transformer working again", "https://i.pinimg.com/originals/14/f1/5c/14f15cc3bbc780abdfecafa0f94024e1.jpg", "https://youtu.be/HNjxxk3eWKk"));

        //this is default tab selected
        setBannerMoviesPagerAdapter(homeBannerList);

        categoryTab.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                switch (tab.getPosition()){
                    case 1:
                        setBannerMoviesPagerAdapter(vipHourBannerList);
                        return;
                    case 2:
                        setBannerMoviesPagerAdapter(prophecyBannerList);
                        return;
                    case 3:
                        setBannerMoviesPagerAdapter(testimonyBannerList);
                        return;
                    default:
                        setBannerMoviesPagerAdapter(homeBannerList);

                }

            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });






        List<CategoryItem> homeCatListItem1 = new ArrayList<>();
        homeCatListItem1.add(new CategoryItem(1, "Trailer - I cannot give up now!!!", "https://i.pinimg.com/originals/1a/5e/c6/1a5ec63c50513055ac7674ad65c2e1a1.jpg", "https://youtu.be/7w1YKrHW85c"));
        homeCatListItem1.add(new CategoryItem(2, "Trailer - I must cross the Red Sea", "https://i.pinimg.com/originals/7f/8f/02/7f8f02fdfc2b09de9d01d86395d128b1.jpg", "https://youtu.be/88dHJdCyyBA"));
        homeCatListItem1.add(new CategoryItem(3, "Trailer - I must be better than my Father", "https://i.pinimg.com/originals/ec/60/46/ec604668771e8916466be6835d2ea588.jpg", "https://youtu.be/GsNrJgLSTAM"));
        homeCatListItem1.add(new CategoryItem(4, "My Hair Will Grow Again", "https://i.pinimg.com/originals/14/f1/5c/14f15cc3bbc780abdfecafa0f94024e1.jpg", "https://youtu.be/yau5eQH1K_I"));
        homeCatListItem1.add(new CategoryItem(5, "See how this man got back his transformer working again", "https://i.pinimg.com/originals/7f/8f/02/7f8f02fdfc2b09de9d01d86395d128b1.jpg", "https://youtu.be/HNjxxk3eWKk"));

        List<CategoryItem> homeCatListItem2 = new ArrayList<>();
        homeCatListItem2.add(new CategoryItem(1, "Trailer - I cannot give up now!!!", "https://i.pinimg.com/originals/1a/5e/c6/1a5ec63c50513055ac7674ad65c2e1a1.jpg", "https://youtu.be/7w1YKrHW85c"));
        homeCatListItem2.add(new CategoryItem(2, "Trailer - I must cross the Red Sea", "https://i.pinimg.com/originals/7f/8f/02/7f8f02fdfc2b09de9d01d86395d128b1.jpg", "https://youtu.be/88dHJdCyyBA"));
        homeCatListItem2.add(new CategoryItem(3, "Trailer - I must be better than my Father", "https://i.pinimg.com/originals/ec/60/46/ec604668771e8916466be6835d2ea588.jpg", "https://youtu.be/GsNrJgLSTAM"));
        homeCatListItem2.add(new CategoryItem(4, "My Hair Will Grow Again", "https://i.pinimg.com/originals/14/f1/5c/14f15cc3bbc780abdfecafa0f94024e1.jpg", "https://youtu.be/yau5eQH1K_I"));
        homeCatListItem2.add(new CategoryItem(5, "See how this man got back his transformer working again", "https://i.pinimg.com/originals/7f/8f/02/7f8f02fdfc2b09de9d01d86395d128b1.jpg", "https://youtu.be/HNjxxk3eWKk"));

        List<CategoryItem> homeCatListItem3 = new ArrayList<>();
        homeCatListItem3.add(new CategoryItem(1, "Trailer - I cannot give up now!!!", "https://i.pinimg.com/originals/1a/5e/c6/1a5ec63c50513055ac7674ad65c2e1a1.jpg", "https://youtu.be/7w1YKrHW85c"));
        homeCatListItem3.add(new CategoryItem(2, "Trailer - I must cross the Red Sea", "https://i.pinimg.com/originals/7f/8f/02/7f8f02fdfc2b09de9d01d86395d128b1.jpg", "https://youtu.be/88dHJdCyyBA"));
        homeCatListItem3.add(new CategoryItem(3, "Trailer - I must be better than my Father", "https://i.pinimg.com/originals/ec/60/46/ec604668771e8916466be6835d2ea588.jpg", "https://youtu.be/GsNrJgLSTAM"));
        homeCatListItem3.add(new CategoryItem(4, "My Hair Will Grow Again", "https://i.pinimg.com/originals/14/f1/5c/14f15cc3bbc780abdfecafa0f94024e1.jpg", "https://youtu.be/yau5eQH1K_I"));
        homeCatListItem3.add(new CategoryItem(5, "See how this man got back his transformer working again", "https://i.pinimg.com/originals/7f/8f/02/7f8f02fdfc2b09de9d01d86395d128b1.jpg", "https://youtu.be/HNjxxk3eWKk"));



        allCategoryList = new ArrayList<>();
        allCategoryList.add(new AllCategory(1,"VIP Hour", homeCatListItem1));
        allCategoryList.add(new AllCategory(2,"VIP Hour", homeCatListItem2));
        allCategoryList.add(new AllCategory(3,"VIP Hour", homeCatListItem3));

        setMainRecycler(allCategoryList);




    }

    private void setBannerMoviesPagerAdapter(List<BannerMovies> bannerMoviesList) {

        bannerMoviesViewPager = findViewById(R.id.banner_viewPager);
        bannerMoviesPagerAdapter = new BannerMoviesPagerAdapter(this, bannerMoviesList);
        bannerMoviesViewPager.setAdapter(bannerMoviesPagerAdapter);
        indicatorTab.setupWithViewPager(bannerMoviesViewPager);

        sliderTimer = new Timer();
        sliderTimer.scheduleAtFixedRate(new AutoSlider(), 4000, 6000);
        indicatorTab.setupWithViewPager(bannerMoviesViewPager, true);

        }

    class AutoSlider extends TimerTask {
        @Override
        public void run() {
            MainActivity.this.runOnUiThread(() ->{

                    if (bannerMoviesViewPager.getCurrentItem() < homeBannerList.size() - 1) {

                        bannerMoviesViewPager.setCurrentItem(bannerMoviesViewPager.getCurrentItem() + 1);
                    }
                    else{
                        bannerMoviesViewPager.setCurrentItem(0);
                    }

            });


        }
    }
        public void setMainRecycler(List<AllCategory> allCategoryList) {

        mainRecycler = findViewById(R.id.main_recycler);
        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this, RecyclerView.VERTICAL, false);
        mainRecycler.setLayoutManager(layoutManager);
        mainRecyclerAdapter = new MainRecyclerAdapter(this, allCategoryList);
        mainRecycler.setAdapter(mainRecyclerAdapter);
        }

}

//模型目录中的项目//

类别项目

public class CategoryItem {


    Integer id;
    String movieName;
    String imageUrl;
    String fileUrl;

    public CategoryItem(Integer id, String movieName, String imageUrl, String fileUrl) {
        this.id = id;
        this.movieName = movieName;
        this.imageUrl = imageUrl;
        this.fileUrl = fileUrl;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getMovieName() {
        return movieName;
    }

    public void setMovieName(String movieName) {
        this.movieName = movieName;
    }

    public String getImageUrl() {
        return imageUrl;
    }

    public void setImageUrl(String imageUrl) {
        this.imageUrl = imageUrl;
    }

    public String getFileUrl() {
        return fileUrl;
    }

    public void setFileUrl(String fileUrl) {
        this.fileUrl = fileUrl;
    }
}

所有类别.Class


import java.util.List;

public class AllCategory {



    String categoryTitle;
    Integer categoryId;
    private List<CategoryItem> categoryItemList = null;

    public AllCategory(Integer categoryId, String categoryTitle, List<CategoryItem> categoryItemList) {
        this.categoryTitle = categoryTitle;
        this.categoryId = categoryId;
        this.categoryItemList = categoryItemList;
    }

    public List<CategoryItem> getCategoryItemList() {
        return categoryItemList;
    }

    public void setCategoryItemList(List<CategoryItem> categoryItemList) {
        this.categoryItemList = categoryItemList;
    }

    public String getCategoryTitle(){
        return categoryTitle;
    }

    public void setCategoryTitle(String categoryTitle){
        this.categoryTitle = categoryTitle;
    }

    public Integer getCategoryId() {
        return categoryId;
    }

    public void setCategoryId(Integer categoryId) {
        this.categoryId = categoryId;
    }
}

横幅电影 包 com.kuroniczstudio.splashscreen.model;

公共课 BannerMovies {

Integer id;
String movieName;
String imageUrl;
String fileUrl;

public BannerMovies(Integer id, String movieName, String imageUrl, String fileUrl) {
    this.id = id;
    this.movieName = movieName;
    this.imageUrl = imageUrl;
    this.fileUrl = fileUrl;
}

public Integer getId() {
    return id;
}

public void setId(Integer id) {
    this.id = id;
}

public String getMovieName() {
    return movieName;
}

public void setMovieName(String movieName) {
    this.movieName = movieName;
}

public String getImageUrl() {
    return imageUrl;
}

public void setImageUrl(String imageUrl) {
    this.imageUrl = imageUrl;
}

public String getFileUrl() {
    return fileUrl;
}

public void setFileUrl(String fileUrl) {
    this.fileUrl = fileUrl;
}

}

_____________________________________  

**MainRecyclerAdapter**

    package com.kuroniczstudio.splashscreen.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.kuroniczstudio.splashscreen.CategoryItem;
import com.kuroniczstudio.splashscreen.R;
import com.kuroniczstudio.splashscreen.model.AllCategory;

import java.util.List;

public class MainRecyclerAdapter extends RecyclerView.Adapter<MainRecyclerAdapter.MainViewHolder> {

    Context context;
    List<AllCategory> allCategoryList;

    public MainRecyclerAdapter(Context context, List<AllCategory> allCategoryList) {
        this.context = context;
        this.allCategoryList = allCategoryList;
    }

    @NonNull
    @Override
    public MainViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new MainViewHolder(LayoutInflater.from(context).inflate(R.layout.main_recycler_row_item, parent));
    }

    @Override
    public void onBindViewHolder(@NonNull MainViewHolder holder, int position) {
        holder.categoryName.setText(allCategoryList.get(position).getCategoryTitle());

    }

    @Override
    public int getItemCount() {
        return allCategoryList.size();
    }

    public static final class MainViewHolder extends RecyclerView.ViewHolder{

        TextView categoryName;
        RecyclerView itemRecycler;

        public MainViewHolder(@NonNull View itemView) {
            super(itemView);

            categoryName = itemView.findViewById(R.id.item_category);
            itemRecycler = itemView.findViewById(R.id.item_recycler);

        }
    }

    private void setItemRecycler(RecyclerView recyclerView, List<CategoryItem> categoryItemList){

       ItemRecyclerAdapter itemRecyclerAdapter = new ItemRecyclerAdapter(context, categoryItemList);
       recyclerView.setLayoutManager(new LinearLayoutManager(context, RecyclerView.HORIZONTAL, false));
       recyclerView.setAdapter(itemRecyclerAdapter);

    }

}

ItemRecyclerAdapter

package com.kuroniczstudio.splashscreen.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.kuroniczstudio.splashscreen.CategoryItem;
import com.kuroniczstudio.splashscreen.R;

import java.util.List;

public class ItemRecyclerAdapter extends RecyclerView.Adapter<ItemRecyclerAdapter.ItemViewHolder> {

    Context context;
    List<CategoryItem> categoryItemList;
    public ItemRecyclerAdapter(Context context, List<CategoryItem> categoryItemList) {
        this.context = context;
        this.categoryItemList = categoryItemList;
    }

    @NonNull
    @Override
    public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ItemViewHolder(LayoutInflater.from(context).inflate(R.layout.cat_recycler_row_items,parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull ItemViewHolder holder, int position) {



        Glide.with(context).load(categoryItemList.get(position).getImageUrl()).into(holder.itemImage);
    }

    @Override
    public int getItemCount() {
        return categoryItemList.size();
    }

    public static final class ItemViewHolder extends RecyclerView.ViewHolder{

        ImageView itemImage;

        public ItemViewHolder(@NonNull View itemView) {
            super(itemView);

            itemImage = itemView.findViewById(R.id.item_image);
        }
    }
}

BannerMoviesPagerAdapter

package com.kuroniczstudio.splashscreen.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;

import com.bumptech.glide.Glide;
import com.kuroniczstudio.splashscreen.R;
import com.kuroniczstudio.splashscreen.model.BannerMovies;

import java.util.List;

public class BannerMoviesPagerAdapter extends PagerAdapter {

    Context context;
    List<BannerMovies> bannerMoviesList;

    public BannerMoviesPagerAdapter(Context context, List<BannerMovies> bannerMoviesList) {
        this.context = context;
        this.bannerMoviesList = bannerMoviesList;
    }

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

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view == object;
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
       container.removeView((View) object);
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {

        View view = LayoutInflater.from(context).inflate(R.layout.banner_movie_layout, null);

        ImageView bannerImage = view.findViewById(R.id.banner_image);


        Glide.with(context).load(bannerMoviesList.get(position).getImageUrl()).into(bannerImage);
        container.addView(view);
        return view;




    }
}

android android-glide android-tablayout
3个回答
0
投票

错误本身就告诉你哪里搞砸了。您的项目中有 2 个

CategoryItem
类,具有以下层次结构:

  1. com.kuroniczstudio.splashscreen.CategoryItem
  2. com.kuroniczstudio.splashscreen.model.CategoryItem

您试图同时使用这两种方法,从而造成了冲突。确保您只使用一个类。


0
投票

在您的应用程序中,您有两个名为

CategoryItem
的类。 其中一个有全名:

com.kuroniczstudio.splashscreen.CategoryItem

对方的全名:

com.kuroniczstudio.splashscreen.model.CategoryItem

它们是不同的类别,您无法从一个类别转换为另一类别。

我们无法从代码中得知您向我们展示了为什么会发生这种情况。 首先,您还没有向我们展示

CategoryItem
的两个版本。 并且您遗漏了所有
package
语句。 (所以我们无法判断
CategoryItem
构造函数需要哪个版本的
AllCategory
...)

但是编译错误消息清楚地证明它正在发生。

你可能根本不应该上两门

CategoryItem
课程......


0
投票

免费下载最新版本的 Castle Mod APK,无广告且解锁所有功能。单击下载按钮即可开始观看电影、节目和现场板球比赛。 https://castleappk.org/

© www.soinside.com 2019 - 2024. All rights reserved.