您好,登錄后才能下訂單哦!
本項(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);
}
效果源碼:http://www.itlanbao.com/code/20151116/10000/100646.html
免責(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)容。