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

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

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

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

慕哥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);    }}}我不知道代碼有什么問題,回收視圖不工作,它不顯示任何項目,如果有人能幫助我并注意到我的代碼中有問題,我將不勝感激
查看完整描述

2 回答

?
寶慕林4294392

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

調(diào)用adapter.notifyDataSetChanged()您的查詢完成回調(diào),這將通知適配器列表已更改。發(fā)生這種情況是因為當(dāng)您設(shè)置適配器時,列表是空的,因為查詢在后臺運行。完成后,您必須告訴適配器新數(shù)據(jù)已添加到列表中:


if (e == null) {

    for (ParseObject obj : objList) {

          ...

    }

    adapter.notifyDataSetChanged();

}

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


dbObjects = new ArrayList<>();

adapter = new CategoryRAdapter(this, dbObjects);

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


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

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

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

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


查看完整回答
反對 回復(fù) 2023-06-04
  • 2 回答
  • 0 關(guān)注
  • 189 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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