title: When scrolling down and up, a recycle view, custom views in items, disappeares
body: <p>I have a problem with a disappearing of a custom view, which I've created programmatically and added to the item container (RelativeLayout), when I scroll it down and up. It builds successfully. <a href="https://i.stack.imgur.com/VrUnK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VrUnK.png" alt="enter image description here"></a></p>
  
  <p>But after scrolling, I have this result in the same item - an empty container..<a href="https://i.stack.imgur.com/EUQaX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EUQaX.png" alt="enter image description here"></a></p>
  
  <p>Custom View </p>
  
  <pre><code>public class WaveFormView extends View {
  Paint p;
  Paint pTop;
  Paint pBottom;
  Rect rect;
  Rect rect1;
  int [] amplitudeArray;
  int amplitudeArraySize;
  int leftPointX;
  int rightPointX;
  int index;
  
  boolean isPlay;
  
  public static final int MAX_AMPLITUDE = 32;//was 1000
  public static final int SIZE_OF_BAR_WAVE_FORM = 98;
  public static final int BAR_SIZE_AND_INTERVAL = 5;
  
  
  private static final float screenDensity = Utils.getDisplayDensity();
  
  public WaveFormView(Context context, int [] amplitudeArray, boolean isPlay, int index) {
      super(context);
      p = new Paint();
      p.setColor(getResources().getColor(R.color.color_wave_from_grey));
  
      pTop = new Paint();
      pTop.setColor(getResources().getColor(R.color.color_wave_form_play_top));
  
      pBottom = new Paint();
      pBottom.setColor(getResources().getColor(R.color.color_wave_form_play_bottom));
  
      this.amplitudeArray = amplitudeArray;
      amplitudeArraySize = amplitudeArray.length;
      this.isPlay = isPlay;
      this.index = index;
  }
  
  @Override
  protected void onDraw(Canvas canvas) {
      if(!isPlay){
          buildWaveForm(canvas);
      }
      else{
          buildWaveFormWhenPlay(canvas);
      }
  
  }
  
  private void buildWaveForm(Canvas canvas){
  
      int oneDp = (int) (1*screenDensity);
      int fourDp = (int) (4*screenDensity);
      int amplitudeDp = 0;
      int startBottomY = (int) (MAX_AMPLITUDE*screenDensity) + oneDp;
      p.setColor(getResources().getColor(R.color.color_wave_from_grey));
      for (int i = 0; i &lt; amplitudeArraySize; i++){
          p.setStyle(Paint.Style.FILL_AND_STROKE);
          leftPointX += oneDp;
          rightPointX = leftPointX+fourDp;
          amplitudeDp  = (int) (amplitudeArray[i]*screenDensity);
          rect = new Rect(leftPointX, startBottomY, rightPointX, startBottomY + amplitudeDp);
          rect1 = new Rect(leftPointX, startBottomY-oneDp-amplitudeDp, rightPointX, startBottomY-oneDp);
          canvas.drawRect(rect, p);
          canvas.drawRect(rect1, p);
          leftPointX+=fourDp;
      }
  }
  
  private void buildWaveFormWhenPlay(Canvas canvas){
    ...}
  </code></pre>
  
  <p>Adapter </p>
  
  <pre><code>public class PostTimeLineAdapter extends   
  RecyclerView.Adapter&lt;PostTimeLineHolder&gt;   ... 
  @Override
  public void onBindViewHolder(final PostTimeLineHolder holder, final int position) { ...
  holder.homeItemContainerWaveForm.addView(new       WaveFormView(context,bufferArray, false, -1));...}
  </code></pre>
  
  <p>Holder</p>
  
  <pre><code>public class PostTimeLineHolder extends RecyclerView.ViewHolder {
  
  ...
  public RelativeLayout homeItemContainerWaveForm;
  
  
  public PostTimeLineHolder(View itemView) {
      super(itemView);
      ...
      this.homeItemContainerWaveForm = (RelativeLayout) itemView.findViewById(R.id.home_item_sound_container_wave_forms);}}
  </code></pre>
  
  <p>Thanks for all your answers!</p>