0
목록을 스크롤 할 때마다 모든 색상이 다른 색상으로 변경되고 목록 상단의 텍스트가 목록의 맨 아래로 이동합니다.스크롤링 RecyclerView 데이터의 색상/텍스트 변경
조각을 새로 고침하면 모든 것이 고정되지만 스크롤 할 때 데이터가 변경됩니다. recyclerview를 재활용 할 수 없도록 설정하면 문제가 해결되지만, 여전히보기를 재활용하기를 원하기 때문에 다른 방법으로보고 싶습니다.
@Override
public TaskViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.trial, parent, false);
TaskViewHolder viewHolder = new TaskViewHolder(view);
return viewHolder;
}
@Override
public void onBindViewHolder(TaskViewHolder holder, int position) {
holder.bindHour(holder, mHomeClasses.get(position));
}
public class TaskViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
//public TextView mDetails;
public ImageView mPlusButton, mMicButton;
public TextView mNewTaskButton;
public TextView mNewExamButton;
//public TextView[] mTasks = new TextView[2];
private ImageView mTakePicButton;
private ImageView mGallaryButton;
public RecyclerView mExamsRecyclerView, mTasksRecyclerView;
public TextView mExamLabel;
public TextView mTaskLabel;
public TaskViewHolder(View itemView) {
super(itemView);
mItemView = itemView;
mTakePicButton = (ImageView)itemView.findViewById(R.id.takePicButton);
mGallaryButton = (ImageView)itemView.findViewById(R.id.gallaryButton);
mMicButton = (ImageView)itemView.findViewById(R.id.micButton);
mExamLabel = (TextView)itemView.findViewById(R.id.examLabel);
mTaskLabel = (TextView)itemView.findViewById(R.id.tasksLabel);
mExamLabel.setText(R.string.examLabel);
mTaskLabel.setText(R.string.taskLabel);
mClassTitle = (TextView)itemView.findViewById(R.id.wc1);
//mDetails = (TextView)itemView.findViewById(R.id.details);
mPlusButton = (ImageView) itemView.findViewById(R.id.plusButton);
// mTasks[0] = (TextView)itemView.findViewById(R.id.task1);
// mTasks[1] = (TextView)itemView.findViewById(R.id.task2);
//mExam1 = (TextView)itemView.findViewById(R.id.exam1);
//mExam2 = (TextView)itemView.findViewById(R.id.exam2);
mNewTaskButton = (TextView) itemView.findViewById(R.id.newTaskButton);
mNewExamButton = (TextView) itemView.findViewById(R.id.newExamButton);
mNewTaskButton.setVisibility(View.INVISIBLE);
mNewExamButton.setVisibility(View.INVISIBLE);
m = new MediaPlayer();
mExamsRecyclerView = (RecyclerView) itemView.findViewById(R.id.examRecyclerView);
mTasksRecyclerView = (RecyclerView) itemView.findViewById(R.id.tasksRecyclerView);
public void bindHour(TaskViewHolder holder, HomeClass homeClass){
Drawable background = mClassTitle.getBackground();
if (background instanceof ShapeDrawable) {
((ShapeDrawable)background).getPaint().setColor(homeClass.getColor());
} else if (background instanceof GradientDrawable) {
((GradientDrawable)background).setColor(homeClass.getColor());
} else if (background instanceof ColorDrawable) {
((ColorDrawable)background).setColor(homeClass.getColor());
}
mNewTaskButton.setVisibility(View.INVISIBLE);
mNewExamButton.setVisibility(View.INVISIBLE);
mExamLabel.setText(R.string.examLabel);
mTaskLabel.setText(R.string.taskLabel);
mNewTaskButton.setBackgroundColor(homeClass.getColor());
mNewExamButton.setBackgroundColor(homeClass.getColor());
Resources res = mContext.getResources();
int newColor = mContext.getResources().getColor(R.color.blueGray);
mPlusButton.setColorFilter(newColor, PorterDuff.Mode.SRC_ATOP);
mTakePicButton.setColorFilter(newColor, PorterDuff.Mode.SRC_ATOP);
mGallaryButton.setColorFilter(newColor, PorterDuff.Mode.SRC_ATOP);
mMicButton.setColorFilter(newColor, PorterDuff.Mode.SRC_ATOP);
mExamsRecyclerView.setLayoutManager(new LinearLayoutManager(mContext));
mExamsRecyclerView.setAdapter(homeClass.getExamAdapter(getAdapterPosition()));
mTasksRecyclerView.setLayoutManager(new LinearLayoutManager(mContext));
mTasksRecyclerView.setAdapter(homeClass.getTaskAdapter(getAdapterPosition()));
if (mExamLabel.getText().toString().equals(R.string.examLabel) && (mTaskLabel.getText().toString().equals(R.string.taskLabel))){
Drawable drawable = mContext.getResources().getDrawable(R.drawable.trial_outline);
mExamsRecyclerView.setBackground(drawable);
}
//mTasks[0].setText(homeClass.getTask1());
//mTasks[1].setText(homeClass.getTask2());
mClassTitle.setText(homeClass.getClassName());
//mDetails.setText("");
mPlusButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
animation.setDuration(250);
mPlusButton.startAnimation(animation);
if (mNewExamButton.getVisibility() == View.INVISIBLE) {
mNewTaskButton.setVisibility(View.VISIBLE);
mNewTaskButton.startAnimation(AnimationUtils.loadAnimation(mContext, android.R.anim.slide_in_left));
mNewExamButton.setVisibility(View.VISIBLE);
mNewExamButton.startAnimation(AnimationUtils.loadAnimation(mContext, android.R.anim.slide_in_left));
} else {
mNewTaskButton.setVisibility(View.INVISIBLE);
mNewTaskButton.startAnimation(AnimationUtils.loadAnimation(mContext, android.R.anim.slide_out_right));
mNewExamButton.setVisibility(View.INVISIBLE);
mNewExamButton.startAnimation(AnimationUtils.loadAnimation(mContext, android.R.anim.slide_out_right));
}
}
});
어떻게 요소의 상태를 유지하고 복원 할 수 있습니다. 코드 스 니펫이 도움이 될 것입니다. – user3212386