Cardview一旦它被点击,我试图改变它的背景颜色。这里列出通知历史记录RecyclerView。Cardview颜色只在那个时候改变。如果我返回并再次打开应用程序意味着它不会被更改。我必须做什么?
这是我的适配器类
public class NotificationsAdapter extends RecyclerView.Adapter<NotificationsAdapter.ViewHolder> {
public static final String TAG = "DataViewHolder";
private Context context;
private ArrayList<NotificationsModel> notificationsModelList;
public NotificationsAdapter(Context context, ArrayList<NotificationsModel> notificationsModelList) {
this.context = context;
this.notificationsModelList = notificationsModelList;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.notification_layout, parent, false);
Log.d(TAG, "onCreateViewHolder: ");
return new ViewHolder(v);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
final NotificationsModel notificationsModel = notificationsModelList.get(position);
holder.title_news.setText(notificationsModel.getTitle());
holder.notif_message.setText(notificationsModel.getMessage());
}
@Override
public int getItemCount() {
return notificationsModelList == null ? 0 : notificationsModelList.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
TextView notif_message, title_news;
//Initializing Views
public ViewHolder(View itemView) {
super(itemView);
title_news = (TextView) itemView.findViewById(R.id.title_news);
notif_message = (TextView) itemView.findViewById(R.id.notif_message);
CardView cardView = (CardView) itemView.findViewById(R.id.cardViewLayoutNotif);
itemView.findViewById(R.id.notif_message);
itemView.setOnClickListener(new View.OnClickListener() {
}
});
}
}
}
慕少森
相关分类