滚动向下和向上滚动RecyclerView时遇到问题.这个想法是改变元素的颜色,但是当我向下滚动时,一切都很棒,当滚动向上时 - 不应该着色的元素会改变颜色.
这是我的适配器:
public class NotificationsAdapter extends RecyclerView.Adapter<NotificationsAdapter.ViewHolder> {
private NotificationData notificationData;
private Context mContext;
private ArrayList<NotificationData> infromationList = new ArrayList<>();
public NotificationsAdapter(Context context, ArrayList<NotificationData> infromationList) {
this.infromationList = infromationList;
this.mContext = context;
}
@Override
public NotificationsAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemLayoutView;
ViewHolder viewHolder;
itemLayoutView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.notification_single_item, parent, false);
viewHolder = new ViewHolder(itemLayoutView, viewType);
return viewHolder;
}
@Override
public void onBindViewHolder(NotificationsAdapter.ViewHolder holder, int position) {
notificationData = infromationList.get(position);
holder.notificationDate.setText(convertDate(notificationData.getDate()));
holder.notificationStatus.setText(notificationData.getNotificationStatus());
holder.orderDescription.setText(notificationData.getNotificationLabel());
if ("true".equals(notificationData.getReadStatus())) {
holder.root.setBackgroundColor(mContext.getResources().getColor(R.color.white));
holder.notificationStatus.setTypeface(Typeface.create("sans-serif-light", …Run Code Online (Sandbox Code Playgroud) 我需要获得JsonArray的一个关键名称,所以JSON看起来像这样,请不要,JSON是从数组括号开始的,在它里面它有对象,我猜是因为后端将能够添加对象.
[
{
"tehnology": [ ]
},
{
"science": []
}
]
Run Code Online (Sandbox Code Playgroud)
所以我需要从它的"技术"和"科学"中获取名称,因为json可以动态改变,我该如何实现呢?