title: Switch between RecyclerView layouts when click on AlertDialog item list
body: <p>I have three different layouts <code>cardsListLayout</code> , <code>titleLayout</code> , <code>cardMagazineLayout</code>and there may be more in the future, which used as a views on <code>onCreateViewHolder</code> method.<br/></p>
  
  <p>I want to switch between views in <code>onCreateViewHolder</code> method so when user  choose from AlertDialog list</p>
  
  <p>this onOptionsItemSelected in MainActivity Where there is menu Item "change the layout" so that when the user presses it it appears AlertDialog list</p>
  
  <pre><code>    @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          if (item.getItemId() == R.id.change_layout) {
              AlertDialog.Builder builder = new AlertDialog.Builder(this);
              builder.setTitle(getString(R.string.choose_layout));
  
              String[] layouts = {"Title Layout", "Cards List", "Card Magazine Layout"};
              builder.setItems(layouts, new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int index) {
                      switch (index) {
                          case 0: // Title layout
                              Toast.makeText(MainActivity.this,
                                      "Title layout", Toast.LENGTH_LONG).show();
                              break;
                          case 1: // Cards List
                              Toast.makeText(MainActivity.this,
                                      "Card list", Toast.LENGTH_LONG).show();
                              break;
                          case 2: // Cards Magazine Layout
                              Toast.makeText(MainActivity.this,
                                      "Card Magazine Layout", Toast.LENGTH_LONG).show();
                      }
                  }
              });
  </code></pre>
  
  <p>and this my custom adapter class <code>PostAdapter</code></p>
  
  <pre><code>public class PostAdapter extends RecyclerView.Adapter&lt;PostAdapter.PostViewHolder&gt; {
      private Context context;
      private List&lt;Item&gt; items;
  
      public PostAdapter(Context context, List&lt;Item&gt; items) {
          this.context = context;
          this.items = items;
      }
  
      @NonNull
      @Override
      public PostAdapter.PostViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
          LayoutInflater inflater = LayoutInflater.from(context);
  
  // here's the three layouts that I can't switch between it
  
          View cardsListLayout = inflater.inflate(R.layout.post_item_card_layout, parent, false);
          View titleLayout = inflater.inflate(R.layout.post_item_grid_layout, parent, false);
          View cardMagazineLayout = inflater.inflate(R.layout.card_magazine_layout,parent,false);
  
          return new PostViewHolder(titleLayout);
      }
  
      @Override
      public void onBindViewHolder(@NonNull PostViewHolder holder, int position) {
          final Item item = items.get(position);
          holder.postTitle.setText(item.getTitle());
          final Document document = Jsoup.parse(item.getContent());
          Elements elements = document.select("img");
  
  
          Log.e("CODE", "Image: " + elements.get(0).attr("src"));
  //        Log.d("Text",document.text());
  //        holder.postDescription.setText(document.text());
  
          Glide.with(context).load(elements.get(0).attr("src"))
                  .into(holder.postImage);
  
          holder.itemView.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  Intent intent = new Intent(context, DetailsActivity.class);
                  intent.putExtra("url", item.getUrl());
                  intent.putExtra("title", item.getTitle());
                  intent.putExtra("content", item.getContent());
                  int youtubeThumbnailImagesetVisibility = 0;
  
                  Element element = document.body();
  
                  String youtubeThumbnailImageSrc = "";
                  String youTubeLink = "";
                  for (Element e : element.getElementsByClass
                          ("YOUTUBE-iframe-video")) {
                      youtubeThumbnailImageSrc = e.attr("data-thumbnail-src");
                      youTubeLink = e.attr("src");
                      Log.e("YouTube thumbnail", youtubeThumbnailImageSrc);
                      Log.e("Youtube link", youTubeLink);
                  }
  
                  if (youtubeThumbnailImageSrc.isEmpty()) {
                      youtubeThumbnailImagesetVisibility = 8;
                      intent.putExtra("youtubeThumbnailImagesetVisibility",
                              youtubeThumbnailImagesetVisibility);
                  } else {
                      intent.putExtra("youtubeThumbnailImageSrc", youtubeThumbnailImageSrc);
                      intent.putExtra("youTubeLink", youTubeLink);
                  }
  
  //             String imageSrc = elements.get(0).attr("src");
  //             intent.putExtra("blogImage",imageSrc);
  
                  context.startActivity(intent);
              }
          });
  
      }
  
      @Override
      public int getItemCount() {
          return items.size();
      }
  
      public class PostViewHolder extends RecyclerView.ViewHolder {
  
          ImageView postImage;
          TextView postTitle;
          TextView postDescription;
  
          public PostViewHolder(View itemView) {
              super(itemView);
              postImage = itemView.findViewById(R.id.postImage);
              postTitle = itemView.findViewById(R.id.postTitle);
              postDescription = itemView.findViewById(R.id.postDescription);
  
          }
      }
  
  }
  </code></pre>
  
  <p>I created two different Layout Manager for each one, there's a LinearLayoutManager and GridLayoutManager, currently I used GridLayout so I commented the LinearLayoutManger temporarily until I know how to switch between them</p>
  
  <pre><code>//      linearLayoutManager = new LinearLayoutManager(this);
          gridLayoutManager = new GridLayoutManager(this, 2, RecyclerView.VERTICAL, false);
  //        recyclerView.setLayoutManager(linearLayoutManager);
          recyclerView.setLayoutManager(gridLayoutManager);
  </code></pre>
  
  <p>The result I aspire to
  <br/></p>
  
  <p><img src="https://i.imgur.com/rn55arT.gif" width="400" height="700"></p>