title: The specified child already has a parent, RecyclerView
body: <p>That's my adapter:</p>
  
  <pre><code>public class ListAdapter extends RecyclerView.Adapter&lt;ListAdapter .ViewHolder&gt; {
      private List&lt;String&gt; mDataset;
  
      // Provide a reference to the views for each data item
      // Complex data items may need more than one view per item, and
      // you provide access to all the views for a data item in a view holder
      public static class ViewHolder extends RecyclerView.ViewHolder {
          // each data item is just a string in this case
          public TextView mTextView;
          public ViewHolder(TextView v) {
              super(v);
              mTextView = v;
          }
      }
  
      // Provide a suitable constructor (depends on the kind of dataset)
      public ListAdapter (List&lt;String&gt; myDataset) {
          mDataset = myDataset;
      }
  
      // Create new views (invoked by the layout manager)
      @Override
      public ListAdapter .ViewHolder onCreateViewHolder(ViewGroup parent,
                                                     int viewType) {
          // create a new view
          View v = LayoutInflater.from(parent.getContext())
                  .inflate(R.layout.item_list_out_in, parent, false);
  
          TextView itemList = (TextView) v.findViewById(R.id.item_list);
          ViewHolder vh = new ViewHolder(itemList);
          return vh;
      }
  
      // Replace the contents of a view (invoked by the layout manager)
      @Override
      public void onBindViewHolder(ViewHolder holder, int position) {
          // - get element from your dataset at this position
          // - replace the contents of the view with that element
          holder.mTextView.setText(mDataset.get(position));
      }
  
      // Return the size of your dataset (invoked by the layout manager)
      @Override
      public int getItemCount() {
          return mDataset.size();
      }
  }
  </code></pre>
  
  <p>That's the fragment:</p>
  
  <pre><code>public class OutInListFragment extends Fragment {
      private RecyclerView mRecyclerView;
      private LinearLayoutManager mLayoutManager;
      private ListAdapter mAdapter;
      private List&lt;String&gt; list = new ArrayList&lt;String&gt;();
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          // Inflate the layout for this fragment
          View view= inflater.inflate(R.layout.fragment_in_out_list, container, false);
          mRecyclerView = (RecyclerView) view.findViewById(R.id.list_in_out);
          if(mRecyclerView!=null){
              Bundle bundle=getArguments();
              Cursor listCursor = getList(bundle.getInt("day"),bundle.getInt("month"),bundle.getInt("year"));
              // use this setting to improve performance if you know that changes
              // in content do not change the layout size of the RecyclerView
              mRecyclerView.setHasFixedSize(true);
  
              // use a linear layout manager
              mLayoutManager = new LinearLayoutManager(getContext());
              mRecyclerView.setLayoutManager(mLayoutManager);
  
              if(listCursor.getCount()&gt;0) {
                  listCursor.moveToFirst();
                  int i = 0, index;
                  while (!listCursor.isAfterLast()) {
                      index = listCursor.getColumnIndex("amount");
                      list.add(listCursor.getString(index));
                      listCursor.moveToNext();
                      i++;
                  }
                  listCursor.close();
              }else{
                 list.add("0");
              }
              // specify an adapter (see also next example)
              mAdapter = new ListAdapter(list);
              mRecyclerView.setAdapter(mAdapter);
          }else{
              Toast.makeText(getContext(),"Error", Toast.LENGTH_SHORT).show();
          }
          return view;
      }
  }
  </code></pre>
  
  <p>I get this error:</p>
  
  <blockquote>
    <p>java.lang.IllegalStateException: The specified child already has a
    parent. You must call removeView() on the child's parent first.</p>
  </blockquote>