我在這裏得到了問題。在綁定數據時,不能使用公共對象。我應該創建一個從其他類獲取數據並將文本設置爲某個XML的類。RecyclerView onBind,沒有綁定數據
public class EventsAdapter extends
RecyclerView.Adapter<RecyclerView.ViewHolder>{
private List<LauncherActivity.ListItem> listItems;
private Context context;
public EventsAdapter(List<LauncherActivity.ListItem> listItems, Context context) {
this.listItems = listItems;
this.context = context;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.event_list, parent, false);
return new ViewHolder(v);
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
LauncherActivity.ListItem listItem = listItems.get(position);
holder.
}
@Override
public int getItemCount() {
return listItems.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
public TextView textHeading = null;
public TextView textDescription = null;
public ViewHolder(View itemView) {
super(itemView);
textHeading = (TextView)itemView.findViewById(R.id.viewHead);
textDescription = (TextView)itemView.findViewById(R.id.viewDesc);
}
}
}
請將代碼添加爲文本。 –
當然,上傳截圖比在一個問題中複製粘貼代碼更困難。曾經想過可能想要獲取代碼並進行編輯的人,以便他們能夠提出答案? –
讓我編輯這個問題,請:) :) – prazeev