Elements get lost in Recyclerview
<p>I have a RecyclerView in my app, which gets filled up by my listadapter. But some elements gets lost after scrolling or even don't get shown at the start. Here I call the ListAdapter in my Activity:</p>

<pre><code>ListAdapter adapter = new ListAdapter(posts, new View.OnClickListener() {
                @Override
                public void onClick(final View v) {
                    new Thread(new Runnable() {
                        @Override
                        public void run() {
                            final PostViewHolder holder = new PostViewHolder(v);
                            final Intent intent = new Intent(MainActivity.this, PostViewActivity.class);
                            intent.setAction(Intent.ACTION_SEND);
                            intent.setType("image/png");
                            final int type = Integer.parseInt((String) holder.cardView.getTag(R.string.ident_type));
                            Log.e("TYPE", "" + type);
                            final String username = (String) holder.cardView.getTag(R.string.ident_username);

                            if (type == 2) {

                                holder.imagePost.setTransitionName(getString(R.string.transition_image));
                                PostViewActivity post;

                                int postWidth = 0;
                                int postHeight = 0;
                                postWidth = holder.imagePost.getWidth();
                                postHeight = holder.imagePost.getHeight();
                                Drawable drawable = holder.imagePost.getDrawable();
                                Bitmap photo = ((BitmapDrawable) drawable).getBitmap();
                                String path = MediaStore.Images.Media.insertImage(getContentResolver(), photo, "pic", null);
                                Uri uri = Uri.parse(path);
                                intent.putExtra(Intent.EXTRA_STREAM, uri);
                                intent.putExtra("dim", postWidth + "/" + postHeight);

                            } else {

                            }
                            activity.runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    ActivityOptionsCompat options;
                                    Pair&lt;View, String&gt; imagePair;
                                    if (type == 2) {
                                        imagePair = Pair.create((View) holder.imagePost, getString(R.string.transition_image));
                                        options = ActivityOptionsCompat.makeSceneTransitionAnimation(MainActivity.this, imagePair);
                                    } else {
                                        options = ActivityOptionsCompat.makeSceneTransitionAnimation(MainActivity.this);
                                    }
                                    String id = (String) holder.cardView.getTag(R.string.ident_id);
                                    intent.putExtra("type", type);
                                    intent.putExtra("username", username);
                                    intent.putExtra("id", id);
                                    startActivity(intent, options.toBundle());
                                }
                            });


                        }
                    }).start();
                }
            }, width, height, context, activity);
            RecyclerView rv = (RecyclerView) findViewById(R.id.user_interface_recycler);
            StaggeredGridLayoutManager lm = new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL);
            rv.setLayoutManager(lm);
            rv.setAdapter(adapter);
</code></pre>

<p>And here is the listadapter itself:</p>

<pre><code>public class ListAdapter extends RecyclerView.Adapter&lt;ListAdapter.PostViewHolder&gt; {
List&lt;Post&gt; posts;
View.OnClickListener listener;
int width;
int height;
private Context context;
public static final String URL = "http://" + Connection.HOSTNAME + "/story/images/";
MainActivity activity;

public ListAdapter(List&lt;Post&gt; posts, View.OnClickListener listener, int width, int height, Context context, MainActivity activity) {
    this.posts = posts;
    this.listener = listener;
    this.width = width;
    this.height = height;
    this.context = context;
    this.activity = activity;
}

int placeholder = 0;

@Override
public int getItemCount() {
    return posts.size();
}

@Override
public PostViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
    View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.insert_layout, viewGroup, false);
    PostViewHolder pvh = new PostViewHolder(v);
    return pvh;
}

@Override
public void onBindViewHolder(final PostViewHolder postViewHolder, int i) {
    Log.e("NUMBER" + i, posts.get(i).getType()+"");
    switch (posts.get(i).getType()) {
        case 1:
            postViewHolder.layoutPhoto.setVisibility(View.GONE);
            textPost(postViewHolder, i);
            break;
        case 2:
            postViewHolder.layoutText.setVisibility(View.GONE);
            imagePost(postViewHolder, i);
            break;
    }
}

private void imagePost(final PostViewHolder postViewHolder, final int i) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    new Thread(new Runnable() {
        @Override
        public void run() {
            String mainText = posts.get(i).getText();
            if (mainText.length() &gt; 100 &amp;&amp; posts.get(i).getType() == 2) {
                mainText = mainText.substring(0, 100);
                mainText += "(...)";
            }


            Calendar calendar = Calendar.getInstance();
            calendar.setTimeInMillis(posts.get(i).getTime());
            if (posts.get(i).getTime() &gt; MainActivity.minTime) {
                MainActivity.minTime = posts.get(i).getTime();
            }
            int mYear = calendar.get(Calendar.YEAR);
            int mMonth = calendar.get(Calendar.MONTH);
            int mDay = calendar.get(Calendar.DAY_OF_MONTH);
            int mMin = calendar.get(Calendar.MINUTE);
            int mHour = calendar.get(Calendar.HOUR);
            String mmin;
            if (mMin &lt; 10) {
                mmin = 0 + "" + mMin;
            } else {
                mmin = Integer.toString(mMin);
            }
            String mhour;
            if (mHour &lt; 10) {
                mhour = 0 + "" + mHour;
            } else {
                mhour = Integer.toString(mHour);
            }
            String resultdate = mDay + "." + (mMonth + 1) + "." + mYear + " " + mhour + ":" + mmin;
            String storyName = posts.get(i).getStory().getName();
            String insertText = posts.get(i).getText() + " by " + posts.get(i).getUsername() + "\n" + resultdate + "\n " + storyName;
            final Spannable spannable = new SpannableString(insertText);
            spannable.setSpan(new ForegroundColorSpan(context.getResources().getColor(R.color.colorAccent)), (posts.get(i).getText() + " by ").length(), insertText.length() - resultdate.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            spannable.setSpan(new ForegroundColorSpan(context.getResources().getColor(R.color.colorDezent)), posts.get(i).getText().length(), (posts.get(i).getText() + " by ").length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            spannable.setSpan(new RelativeSizeSpan(1f), (posts.get(i).getText() + " by " + posts.get(i).getUsername() + "\n").length(), insertText.length() - storyName.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            spannable.setSpan(new ForegroundColorSpan(context.getResources().getColor(R.color.colorDezent)), (posts.get(i).getText() + " by " + posts.get(i).getUsername() + "\n").length(), insertText.length() - storyName.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            spannable.setSpan(new ForegroundColorSpan(context.getResources().getColor(R.color.colorPrimaryDark)), insertText.length() - storyName.length(), insertText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

            activity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Log.e("photo", "photo");
                    postViewHolder.cv.setTag(R.string.ident_type, Integer.toString(posts.get(i).getType()));
                    postViewHolder.cv.setTag(R.string.ident_id, Integer.toString(posts.get(i).getID()));
                    int imgWidth = (int) ((float) width / 6);
                    int imgHeight = (int) ((float) width / 6);
                    Picasso.with(context).load(ListAdapter.URL + posts.get(i).getImageUser() + ".png").transform(new CircleTransform()).resize(imgWidth, imgHeight).centerCrop().into(postViewHolder.photoUserPhoto);
                    Picasso.with(context).load(ListAdapter.URL + posts.get(i).getImagePost() + ".png").resize(width, 500).centerCrop().into(postViewHolder.photoPostPhoto);
                    postViewHolder.photoText.setText(spannable);
                    postViewHolder.photoPostPhoto.setTransitionName("");
                    postViewHolder.itemView.setOnClickListener(listener);
                    postViewHolder.cv.setTag(R.string.ident_username, posts.get(i).getUsername());
                }
            });

        }
    }

    ).start();

}

private void textPost(final PostViewHolder postViewHolder, final int i) {
    new Thread(new Runnable() {
        @Override
        public void run() {
            String mainText = posts.get(i).getText();
            Long postdate = posts.get(i).getTime();
            String username = posts.get(i).getUsername();
            //Bitmap userPhoto = posts.get(i).getImageUser();


            Calendar calendar = Calendar.getInstance();
            calendar.setTimeInMillis(posts.get(i).getTime());
            if (posts.get(i).getTime() &gt; MainActivity.minTime) {
                MainActivity.minTime = posts.get(i).getTime();
            }

            int mYear = calendar.get(Calendar.YEAR);
            int mMonth = calendar.get(Calendar.MONTH);
            int mDay = calendar.get(Calendar.DAY_OF_MONTH);
            int mMin = calendar.get(Calendar.MINUTE);
            int mHour = calendar.get(Calendar.HOUR);
            String mmin;
            if (mMin &lt; 10) {
                mmin = 0 + "" + mMin;
            } else {
                mmin = Integer.toString(mMin);
            }
            String mhour;
            if (mHour &lt; 10) {
                mhour = 0 + "" + mHour;
            } else {
                mhour = Integer.toString(mHour);
            }
            String resultdate = mDay + "." + (mMonth + 1) + "." + mYear + " " + mhour + ":" + mmin;
            String storyName = posts.get(i).getStory().getName();
            String insertText = posts.get(i).getText() + " by " + posts.get(i).getUsername() + "\n" + resultdate + "\n " + storyName;
            final Spannable spannable = new SpannableString(insertText);
            spannable.setSpan(new ForegroundColorSpan(context.getResources().getColor(R.color.colorAccent)), (posts.get(i).getText() + " by ").length(), insertText.length() - resultdate.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            spannable.setSpan(new ForegroundColorSpan(context.getResources().getColor(R.color.colorDezent)), posts.get(i).getText().length(), (posts.get(i).getText() + " by ").length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            spannable.setSpan(new RelativeSizeSpan(0.8f), (posts.get(i).getText() + " by " + posts.get(i).getUsername() + "\n").length(), insertText.length() - storyName.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            spannable.setSpan(new ForegroundColorSpan(context.getResources().getColor(R.color.colorDezent)), (posts.get(i).getText() + " by " + posts.get(i).getUsername() + "\n").length(), insertText.length() - storyName.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            spannable.setSpan(new ForegroundColorSpan(context.getResources().getColor(R.color.colorPrimaryDark)), insertText.length() - storyName.length(), insertText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

            activity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Log.e("text", "text");
                    postViewHolder.textUser.setText(spannable);
                    int imgWidth = (int) ((float) width / 6);
                    int imgHeight = (int) ((float) width / 6);
                    Picasso.with(context).load(ListAdapter.URL + posts.get(i).getImageUser() + ".png").transform(new CircleTransform()).resize(imgWidth, imgHeight).centerCrop().into(postViewHolder.textUserPhoto);
                    postViewHolder.itemView.setOnClickListener(listener);
                    postViewHolder.cv.setTag(R.string.ident_type, Integer.toString(posts.get(i).getType()));
                    postViewHolder.cv.setTag(R.string.ident_id, Integer.toString(posts.get(i).getID()));
                    postViewHolder.cv.setTag(R.string.ident_username, posts.get(i).getUsername());
                }
            });
        }
    }).start();

}

@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
    super.onAttachedToRecyclerView(recyclerView);
}


public class PostViewHolder extends RecyclerView.ViewHolder {
    CardView cv;

    LinearLayout layoutPhoto;
    TextView photoText;
    ImageView photoPostPhoto;
    ImageView photoUserPhoto;

    LinearLayout layoutText;
    TextView textUser;
    ImageView textUserPhoto;

    PostViewHolder(View itemView) {
        super(itemView);
        cv = (CardView) itemView.findViewById(R.id.cv);

        photoText = (TextView) itemView.findViewById(R.id.photo_user_text);
        photoPostPhoto = (ImageView) itemView.findViewById(R.id.photo_postPhoto);
        layoutPhoto = (LinearLayout) itemView.findViewById(R.id.insert_layout_photo);
        photoUserPhoto = (ImageView) itemView.findViewById(R.id.photo_username_photo);

        layoutText = (LinearLayout) itemView.findViewById(R.id.insert_layout_text);
        textUser = (TextView) itemView.findViewById(R.id.text_user_text);
        textUserPhoto = (ImageView) itemView.findViewById(R.id.text_username_photo);
    }

}

}
</code></pre>

<p>Where could the problem be? Thanks!</p>

<p>Edit:</p>

<p>fragment_main:</p>

<pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"&gt;
&lt;android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/activity_main_swipe_refresh_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"&gt;

    &lt;android.support.v7.widget.RecyclerView
        android:id="@+id/post_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"&gt;


    &lt;/android.support.v7.widget.RecyclerView&gt;


&lt;/android.support.v4.widget.SwipeRefreshLayout&gt;
</code></pre>

<p></p>

<p>activity_main (This is a coordinatorLayout, but this gets cut away. Don't know why):</p>

<p>
</p>

<pre><code>&lt;android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="@dimen/appbar_padding_top"
    android:theme="@style/AppTheme.AppBarOverlay"&gt;

    &lt;android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay"
        app:layout_scrollFlags="scroll|enterAlways|snap"&gt;
    &lt;/android.support.v7.widget.Toolbar&gt;

    &lt;android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" /&gt;

&lt;/android.support.design.widget.AppBarLayout&gt;

&lt;android.support.v4.view.ViewPager
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" /&gt;

&lt;android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="end|bottom"
    android:layout_margin="@dimen/fab_margin"
    android:src="@android:drawable/ic_dialog_email" /&gt;
</code></pre>

<p></p>