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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Androidx RecycleView 不顯示帶有解析服務(wù)器的項(xiàng)目

Androidx RecycleView 不顯示帶有解析服務(wù)器的項(xiàng)目

慕哥6287543 2023-06-04 17:01:49
這是我的回收視圖適配器類別適配器類public class CategoryRAdapter extends RecyclerView.Adapter<CategoryRAdapter.MyViewHolder> {private Context mcontext;private List<Food> mData;RequestOptions option;public CategoryRAdapter(Context mcontext, List<Food> mData) {    this.mcontext = mcontext;    this.mData = mData;    option = new RequestOptions().centerCrop().placeholder(R.drawable.loading_shape).error(R.drawable.loading_shape);}@Overridepublic MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.food_row, parent, false);    return new MyViewHolder(view);}@Overridepublic void onBindViewHolder(MyViewHolder holder, int position) {    Food current = mData.get(position);    holder.tv_Name.setText(current.getName());    holder.tv_Rating.setText(current.getRating());    holder.tv_Descip.setText(current.getDescrip());    holder.tv_Category.setText(current.getCateg());    Glide.with(mcontext).load(mData.get(position).getImages()).apply(option).into(holder.img_Thumbnail);}@Overridepublic int getItemCount() {    return mData.size();}public class MyViewHolder extends RecyclerView.ViewHolder {    TextView tv_Name;    TextView tv_Rating;    TextView tv_Descip;    TextView tv_Category;    ImageView img_Thumbnail;    public MyViewHolder(View itemView) {        super(itemView);        tv_Name = itemView.findViewById(R.id.food_name);        tv_Rating = itemView.findViewById(R.id.rating);        tv_Descip = itemView.findViewById(R.id.desc);        tv_Category = itemView.findViewById(R.id.category);        img_Thumbnail = itemView.findViewById(R.id.thumbnail);    }}}我不知道代碼有什么問題,回收視圖不工作,它不顯示任何項(xiàng)目,如果有人能幫助我并注意到我的代碼中有問題,我將不勝感激
查看完整描述

2 回答

?
寶慕林4294392

TA貢獻(xiàn)2021條經(jīng)驗(yàn) 獲得超8個(gè)贊

調(diào)用adapter.notifyDataSetChanged()您的查詢完成回調(diào),這將通知適配器列表已更改。發(fā)生這種情況是因?yàn)楫?dāng)您設(shè)置適配器時(shí),列表是空的,因?yàn)椴樵冊(cè)诤笈_(tái)運(yùn)行。完成后,您必須告訴適配器新數(shù)據(jù)已添加到列表中:


if (e == null) {

    for (ParseObject obj : objList) {

          ...

    }

    adapter.notifyDataSetChanged();

}

此外,在發(fā)送查詢之前創(chuàng)建您的適配器,否則可能會(huì)導(dǎo)致NullPointerException在下一條語句執(zhí)行之前加載數(shù)據(jù)(這種可能性很小,但絕對(duì)不會(huì)影響安全)。


dbObjects = new ArrayList<>();

adapter = new CategoryRAdapter(this, dbObjects);

ParseQuery<ParseObject> query = ParseQuery.getQuery("Category");


查看完整回答
反對(duì) 回復(fù) 2023-06-04
?
莫回?zé)o

TA貢獻(xiàn)1865條經(jīng)驗(yàn) 獲得超7個(gè)贊

我建議您使用 RxJava2 來使用異步方法,這太棒了……關(guān)于這個(gè)問題,當(dāng)您已經(jīng)使用 ArrayList 創(chuàng)建適配器時(shí),您的數(shù)據(jù)可能還沒有準(zhǔn)備好。

嘗試將 ) 移動(dòng)到創(chuàng)建食物對(duì)象后的recyclerView.setAdapter(內(nèi)部。FindCallback


查看完整回答
反對(duì) 回復(fù) 2023-06-04
  • 2 回答
  • 0 關(guān)注
  • 226 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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