码迷,mamicode.com
首页 > 其他好文 > 详细

Recycle多条目的适配器

时间:2017-10-25 19:53:22      阅读:99      评论:0      收藏:0      [点我收藏+]

标签:ebe   ada   long   tran   count   manage   banner   horizon   apt   

public class HomeAdapter extends RecyclerView.Adapter {
    HomeBean.DataBean list;
    ArrayList<User> a5list;
    ArrayList<User> golist;
    ArrayList<User> zulist;
    Context context;
    ArrayList<String> slist;
    ArrayList<String> klist;
    private  enum  Item_Type{

        Typeone ,Typetwo,Typethree,Typefour

    }
    public HomeAdapter(HomeBean.DataBean list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
    {
        if(viewType==Item_Type.Typeone.ordinal()) {
            View mView = LayoutInflater.from(context).inflate(R.layout.recycle_item_a, null);
            Item_aBanner viewHolder = new Item_aBanner(mView);
            return viewHolder;
        }else if(viewType==Item_Type.Typetwo.ordinal()) {
            View mView=LayoutInflater.from(context).inflate(R.layout.recycle_item_b,null);
            Item_b vb=new Item_b(mView);
            return vb;
        }else if(viewType==Item_Type.Typethree.ordinal()){
            View mView=LayoutInflater.from(context).inflate(R.layout.recycle_item_c,null);
            Item_c vb=new Item_c(mView);
            return vb;
        }else if(viewType==Item_Type.Typefour.ordinal()){
            View mView=LayoutInflater.from(context).inflate(R.layout.recycle_item_d,null);
            Item_d vb=new Item_d(mView);
            return vb;
        }else{
            View mView=LayoutInflater.from(context).inflate(R.layout.recycle_item_e,null);
            Item_e vb=new Item_e(mView);
            return vb;
        }
    }

    @Override
    public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
        if(holder instanceof Item_aBanner){
            slist=new ArrayList();
            klist=new ArrayList<String>();
            for(int i=0;i<list.getAd1().size();i++){
                slist.add(list.getAd1().get(i).getImage());
                klist.add(list.getAd1().get(i).getTitle());
            }
            ((Item_aBanner) holder).mybanner.setImageLoader(new GlideImaGlideImageLoader());
            ((Item_aBanner) holder).mybanner.setBannerAnimation(ZoomOutSlideTransformer.class);
            ((Item_aBanner) holder).mybanner
            .setBannerStyle(BannerConfig.CIRCLE_INDICATOR_TITLE)
                    .setBannerTitles(klist);
            ((Item_aBanner) holder).mybanner.setImages(slist);
            ((Item_aBanner) holder).mybanner.start();

        }else if(holder instanceof Item_b){
            a5list=new ArrayList<User>();
            for (int i=0;i<list.getAd5().size();i++){
                a5list.add(new User(list.getAd5().get(i).getImage(),list.getAd5().get(i).getTitle(),list.getAd5().get(i).getAd_type_dynamic_data()));
            }
            Item2Adapter i2=new Item2Adapter(a5list,context);
            ((Item_b) holder).rc.setItemAnimator(new DefaultItemAnimator());
            ((Item_b) holder).rc.setLayoutManager(new GridLayoutManager(context,4));
            ((Item_b) holder).rc.setAdapter(i2);
            i2.setOnItemClickLitener(new HomeAdapter.OnItemClickLitener()
            {

                @Override
                public void onItemClick(View view, int position)
                {
                    String data_url = a5list.get(position).getData_url();
                    Intent inten = new Intent(context, MyWebView.class);
                    inten.putExtra("url", data_url);
                    context.startActivity(inten);
                }

                @Override
                public void onItemLongClick(View view, int position)
                {
                    Toast.makeText(context, position + " long click",
                            Toast.LENGTH_SHORT).show();
               /* mAdapter.removeData(position);*/
                }
            });
        }else if(holder instanceof Item_d){
            golist=new ArrayList<User>();
            for (int i=0;i<list.getSubjects().size();i++){
                golist.add(new User(list.getSubjects().get(i).getDescImage(),list.getSubjects().get(i).getTitle(),list.getSubjects().get(i).getUrl()));
            }
            ((Item_d) holder).rc2.setLayoutManager(new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.HORIZONTAL));
            ((Item_d) holder).rc2.setAdapter(new Item2Adapter(golist,context));
        }else if(holder instanceof Item_e){
            zulist=new ArrayList<User>();
            for (int i=0;i<list.getDefaultGoodsList().size();i++){
                zulist.add(new User(list.getDefaultGoodsList().get(i).getGoods_img(),list.getDefaultGoodsList().get(i).getGoods_name(),list.getDefaultGoodsList().get(i).getGoods_img()));
            }
            ((Item_e) holder).rc3.setLayoutManager(new GridLayoutManager(context,2));
            ((Item_e) holder).rc3.setAdapter(new Shangpingliebiao(zulist,context));
        }
        else if(holder instanceof Item_c){
            View paomadeng_item = View.inflate(context, R.layout.paomadeng_item, null);
            ((Item_c) holder).vf.addView(paomadeng_item);
            ((Item_c) holder).countdownView.start(9000000);
        }

    }

    @Override
    public int getItemViewType(int position) {
        if(position==0){
            return Item_Type.Typeone.ordinal();
        }else if (position == 1) {
            return Item_Type.Typetwo.ordinal();
        } else if (position == 2) {
            return Item_Type.Typethree.ordinal();
        }else if (position == 3) {
            return Item_Type.Typefour.ordinal();
        }
        return -1;
    }

    @Override
    public int getItemCount()
    {
        return 5;
    }
    public interface OnItemClickLitener
    {
        void onItemClick(View view, int position);
        void onItemLongClick(View view , int position);
    }

    private OnItemClickLitener mOnItemClickLitener;

    public void setOnItemClickLitener(OnItemClickLitener mOnItemClickLitener)
    {
        this.mOnItemClickLitener = mOnItemClickLitener;

    }


}

 

Recycle多条目的适配器

标签:ebe   ada   long   tran   count   manage   banner   horizon   apt   

原文地址:http://www.cnblogs.com/cainiaodongdong/p/7731553.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!