溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

RecyclerView加載不同view實(shí)現(xiàn)效果--IT藍(lán)豹

發(fā)布時(shí)間:2020-07-23 22:31:12 來源:網(wǎng)絡(luò) 閱讀:396 作者:楊光成 欄目:開發(fā)技術(shù)

本項(xiàng)目由開發(fā)者:黃洞洞精心為初學(xué)者編輯RecyclerView的使用方法。
RecyclerView加載不同view實(shí)現(xiàn)效果,支持加載多個(gè)view,并且支持用volley獲取數(shù)據(jù),
項(xiàng)目主要介紹:
初始化視圖:
    mRV=(RecyclerView) findViewById(R.id.rv_basefragment);
        mRV.setLayoutManager(new LinearLayoutManager(this));


 //初始化請求隊(duì)列 queue = Volley.newRequestQueue(this);
//獲取網(wǎng)絡(luò)接口
StringRequest stringRequest=new StringRequest(URL, new Response.Listener<String>() {

            @Override
            public void onResponse(String response) {
                //處理數(shù)據(jù)
                processData(response);
                
            }
        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                System.out.println(error.getMessage()+"ddddddddddddddddddddddddddddddddddddddddddddd");
            }
        });
        
        //將請求加入到隊(duì)列中
        queue.add(stringRequest);

 

 

//視圖綁定
/*
     * onBindViewHolder 根據(jù)ViewHolder_01獲取多個(gè)view
     * */
    @Override
    public void onBindViewHolder(BaseViewHolder holder, int position) {
         switch (superData.get(position).first){
         case COMMUNITY_TOP:
             ((ViewHolder_01)holder).initData(communityBean);
             break;
         case COMMUNITY_OHTER:
             ((ViewHolder_02)holder).initData(superData.get(position));
             break;
     }
    }
    
/*
     * onCreateViewHolder 根據(jù)類型綁定多個(gè)ViewHolder_01,加載多個(gè)不同view
     * */
    @Override
    public BaseViewHolder onCreateViewHolder(ViewGroup arg0, int type) {
        
        switch (type) {
        case COMMUNITY_TOP:
            return new ViewHolder_01(View.inflate(context, R.layout.item_community_top, null),context);
        case COMMUNITY_OHTER:
            return new ViewHolder_02(View.inflate(context, R.layout.item_community_other, null),context);
        }
        
        return new ViewHolder_02(View.inflate(context, R.layout.item_community_other, null),context);
    }

運(yùn)行效果:

  • RecyclerView加載不同view實(shí)現(xiàn)效果--IT藍(lán)豹

效果源碼:http://www.itlanbao.com/code/20151116/10000/100646.html

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI