第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

具有多個視圖的 Android Recycler View

具有多個視圖的 Android Recycler View

江戶川亂折騰 2023-03-09 17:04:13
我正在制作一個應(yīng)用程序,我想在其中將文本、圖像和視頻全部放在單獨的 ViewHolders 中(類似于 Instagram 和 Facebook)。我知道我們必須使用具有多個 ViewTypes 的 Recycler View。我正在使用 firebase 作為我的存儲。我如何從 firebase 檢索項目并將它們放在適當?shù)?ViewHolder 中。請幫我。
查看完整描述

4 回答

?
小唯快跑啊

TA貢獻1863條經(jīng)驗 獲得超2個贊

公共類 GovtjobsAdapter 擴展 RecyclerView.Adapter {


private List<GovtjobBean> govtjobList;


public class MyViewHolder extends RecyclerView.ViewHolder {

    public TextView tv_govtjob_title,tv_govtjob_lastdatetoapply,tv_govtjob_location;


    public MyViewHolder(View view) {

        super(view);

        tv_govtjob_title = (TextView) view.findViewById(R.id.tv_govtjobs_title);

        tv_govtjob_lastdatetoapply = (TextView) view.findViewById(R.id.tv_govtjob_lastdatetoapply);

        tv_govtjob_location = (TextView) view.findViewById(R.id.tv_govtjob_location);

    }

}



public GovtjobsAdapter(List<GovtjobBean> govtjobList) {

    this.govtjobList = govtjobList;

}


@Override

public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

    View itemView = LayoutInflater.from(parent.getContext())

            .inflate(R.layout.govtjob_lists, parent, false);


    return new MyViewHolder(itemView);

}


@Override

public void onBindViewHolder(MyViewHolder holder, int position) {

    GovtjobBean govtjoblist = govtjobList.get(position);

    holder.tv_govtjob_title.setText(govtjoblist.getGovt_title());

    holder.tv_govtjob_lastdatetoapply.setText(govtjoblist.getGovt_lastdatetoapply());

    holder.tv_govtjob_location.setText(govtjoblist.getGovt_location());

}


@Override

public int getItemCount() {

    return govtjobList.size();

}

}


查看完整回答
反對 回復(fù) 2023-03-09
?
人到中年有點甜

TA貢獻1895條經(jīng)驗 獲得超7個贊

您必須使用 recyclerview ViewTypes,檢查此鏈接中的示例:

Android RecyclerView 示例——多個 ViewType

或者你可以使用像 FastAdapter 這樣的庫,它是處理適配器項類型的很棒的庫:

https://github.com/mikepenz/FastAdapter


查看完整回答
反對 回復(fù) 2023-03-09
?
HUH函數(shù)

TA貢獻1836條經(jīng)驗 獲得超4個贊

您將需要創(chuàng)建一個自定義回收器視圖類,您可以在其中重寫 onCreateViewHolder(ViewGroup parent, Int viewType)。


這是我的例子:


(1) 在您的 recyclerview 類中創(chuàng)建自定義視圖持有者類。例子:


class ViewHolderCurrent extends RecyclerView.ViewHolder {


    TextView locationTV;

    TextView conditionTV;

    ...


    public ViewHolderCurrent(View listItemView) {

        super(listItemView);


        locationTV = listItemView.findViewById(R.id.location_main_4);

        conditionTV = listItemView.findViewById(R.id.condition_main_4);

        ...

    }

}

(2) 將 onCreateViewHolder 覆蓋到您的自定義視圖持有者:


@Override

public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

    switch (viewType) {

        case 1:

            View viewCurrent = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item4, parent, false);

            return new ViewHolderCurrent(viewCurrent);


        case 2:

        ...


        case 3:

        ...

    }


    return null;

}

(3)重寫 onBindViewHolder() 以填充您選擇的查看器。例子:


@Override

public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

    switch (holder.getItemViewType()) {

        case 1:

            ViewHolderCurrent viewHolderCurrent = (ViewHolderCurrent) holder;


            viewHolderCurrent.locationTV.setText(*text*);

            viewHolderCurrent.conditionTV.setText(*text*);


            break;


        case 2:

        ...

        }

}

我的完整源代碼在這里


查看完整回答
反對 回復(fù) 2023-03-09
?
紅糖糍粑

TA貢獻1815條經(jīng)驗 獲得超6個贊

您可以使用getItemViewType(int position)適配器的方法來執(zhí)行此操作。在此方法中,您可以檢查當前位置的項目類型(圖像、視頻或文本),并為每個項目返回一個特定值。然后在您的中,onCreateViewHolder(ViewGroup parent, Int viewType)您可以使用該viewType參數(shù)來擴大您的觀點。



查看完整回答
反對 回復(fù) 2023-03-09
  • 4 回答
  • 0 關(guān)注
  • 179 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號