title: How to show total number of recyclerview in a textview in android studio
body: <p>I have data on firebase, the data is shown in recyclerview. I have so many recyclerviews showing. Above a recyclerview I have a textview where I want to show the total number of recyclerviews. I have also a button so that when I click on it does the count and show the result in a textview. In summary: If i click a button i want to see the number of recyclerviews in a textview.</p>
  <p>Here is my .xml code:</p>
  <pre><code> &lt;RelativeLayout
              android:id=&quot;@+id/rlRunning&quot;
              android:background=&quot;#00ff0000&quot;
              android:layout_below=&quot;@+id/rl&quot;
              android:layout_width=&quot;match_parent&quot;
              android:layout_height=&quot;match_parent&quot;&gt;
  
              &lt;TextView
                  android:id=&quot;@+id/del_t&quot;
                  android:text=&quot;mmmm&quot;
                  android:textSize=&quot;30sp&quot;
                  android:layout_width=&quot;wrap_content&quot;
                  android:layout_height=&quot;wrap_content&quot; /&gt;
              &lt;Button
                  android:onClick=&quot;clickMe&quot;
                  android:id=&quot;@+id/btn_t&quot;
                  android:layout_below=&quot;@+id/del_t&quot;
                  android:text=&quot;Click me&quot;
                  android:layout_width=&quot;wrap_content&quot;
                  android:layout_height=&quot;wrap_content&quot; /&gt;
  
              &lt;android.support.v7.widget.RecyclerView
                  android:layout_below=&quot;@+id/btn_t&quot;
                  android:id=&quot;@+id/recyclerview&quot;
                  android:background=&quot;#00ff0000&quot;
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;match_parent&quot;&gt;
              &lt;/android.support.v7.widget.RecyclerView&gt;
          &lt;/RelativeLayout&gt;
  </code></pre>
  <p>Here is my adapter:</p>
  <pre><code>public class BlogzoneImages {
  
      private String ititle, idate, idesc,imageUrl;
  
      public BlogzoneImages(String ititle, String idate, String imageUrl, String idesc ) {
          this.idate = idate;
          this.ititle = ititle;
          this.idesc = idesc;
          this.imageUrl=imageUrl;
      }
  
      public BlogzoneImages() {
      }
  
      public void setImageUrl(String imageUrl) {
          this.imageUrl = imageUrl;
      }
  
      public void setiDate(String idate) {
          this.idate = idate;
      }
  
      public void setiTitle(String ititle) {
          this.ititle = ititle;
      }
  
      public void setiDesc(String idesc) {
          this.idesc = idesc;
      }
  
      public String getImageUrl() {
          return imageUrl;
      }
  
      public String getiDate() {
          return idate;
      }
  
      public String getiTitle() {
          return ititle;
      }
  
      public String getiDesc() {
          return idesc;
      }
  }
  </code></pre>
  <p>Here is how I am getting the data to display in MainActivity.java</p>
  <pre><code>protected void loadImage_setups() {
          mAuth.addAuthStateListener(mAuthListener);
          FirebaseRecyclerAdapter&lt;BlogzoneImages, BlogzoneViewHolder2&gt; FBRA_Images = new FirebaseRecyclerAdapter&lt;BlogzoneImages, BlogzoneViewHolder2&gt;(
                  BlogzoneImages.class,
                  R.layout.setups_card,
                  BlogzoneViewHolder2.class,
                  image_Database
  
          ) {
              @Override
              protected void populateViewHolder(BlogzoneViewHolder2 viewHolder, BlogzoneImages model, int position) {
                  final String post_key = getRef(position).getKey().toString();
                  viewHolder.setiDate(model.getiDate());
                  viewHolder.setiTitle(model.getiTitle());
                  viewHolder.setiDesc(model.getiDesc());
                  viewHolder.setImageUrl(getApplicationContext(), model.getImageUrl());
                  viewHolder.mView2.setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View view) {
                          //   Intent singleActivity = new Intent(MainActivity.this, SinglePostActivity.class);
                          //   singleActivity.putExtra(&quot;PostID&quot;, post_key);
                          //   startActivity(singleActivity);
                      }
                  });
              }
          };
          recyclerView.setAdapter(FBRA_Images);
      }
  
      public static class BlogzoneViewHolder2 extends RecyclerView.ViewHolder {
          View mView2;
  
          public BlogzoneViewHolder2(View itemView2) {
              super(itemView2);
              mView2 = itemView2;
          }
  
          public void setiDate(String idate) {
              TextView post_date = mView2.findViewById(R.id.setup_date);
              post_date.setText(idate);
          }
  
          public void setiTitle(String ititle) {
              TextView post_title = mView2.findViewById(R.id.setup_title);
              post_title.setText(ititle);
          }
  
          public void setiDesc(String idesc) {
              TextView post_desc = mView2.findViewById(R.id.setup_desc);
              post_desc.setText(idesc);
          }
  
          public void setImageUrl(Context ctx, String imageUrl) {
              ImageView post_image = mView2.findViewById(R.id.setup_image);
              Picasso.with(ctx).load(imageUrl).into(post_image);
          }
      }
  </code></pre>
  <p>All this is well, the data is showing nicely on recyclerview.</p>
  <p>My worry now is to show the total number of these recyclerviews in a texview when i click the button.</p>
  <p>I have tried this in MainActivity.java:</p>
  <pre><code>int count = 0;
      public void showTotal() {
          RecyclerView recyclerView = (RecyclerView)findViewById(R.id.recyclerview);
          if (recyclerView.getAdapter() != null) {
              count = recyclerView.getAdapter().getItemCount();
          }
          TextView tvvv = (TextView)findViewById(R.id.del_t);
          tvvv.setText(count);
      }
      public void clickMe(View view) {
          showTotal();
      }
  </code></pre>
  <p>When i click the button, the app crashes. I have also tried this:</p>
  <pre><code>public void showTotal() {
          RecyclerView recyclerView = (RecyclerView)findViewById(R.id.recyclerview);
          int itemCount = recyclerView.getAdapter().getItemCount();
          TextView tvvv = (TextView)findViewById(R.id.del_t);
          tvvv.setText(itemCount);
      }
      public void clickMe(View view) {
          showTotal();
      }
  </code></pre>
  <p>When I click the button, the app crashes again. So now I am stuck. I have no idea how to solve this. My question is, how can i show the total number of recyclerviews in a TextView after a button click?</p>