我已經添加項RecyclerView和設置適配器但它示出了零個元素。意味着清單是空的。請幫我Recyclerview表示0商品
ChatAdapter.java
public class ChatAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
Context context;
ArrayList<ChatModel> chatList;
public ChatAdapter(Context context, ArrayList<ChatModel> chatList) {
this.context = context;
this.chatList = chatList;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new TextInViewHolder(LayoutInflater.from(context).inflate(R.layout.chat_list_in_text, parent, false));
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
TextInViewHolder hold = (TextInViewHolder) holder;
hold.tvIncText.setText(chatList.get(position).getText());
}
@Override
public int getItemCount() {
return 0;
}
public class TextInViewHolder {
public TextInViewHolder(View itemView) {
super(itemView);
}
}
}
在getItemCount你返回0,回報您的chatList大小 –
@BharathKumar請不要在評論專門回答當答案已經被公佈 –
@Pavneet_Singh和爲貴,請不要回答重複 –