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)); 
       } 
      } 
     }); 

答えて

0

右、それはRecyclerViewと "問題" です。彼はビューを削除し、新しいアイテムを作成します。要素の状態を保持し、リサイサーが彼を作成したいときに復元することができます。

+0

どのように私は要素の状態を保持し、復元しますか。コードスニペットが役立つでしょう – user3212386

関連する問題