title: how to retrieve specific users in swipe refresh layout
body: <p>I am creating a matrimony application and using firebase as database, in which first fragment is search profile.In search profile it shows all the profiles from database may it be male or female but I want to show male profiles for female user and vice versa. And every user is authenticated user.
    I have tried different queries but did'nt succeed. Please help to figure out the issue.</p>
  
  <p>These are users in firebase:</p>
  
  <p><a href="https://i.stack.imgur.com/hWb5c.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hWb5c.png" alt="These are users in firebase"></a></p>
  
  <p>These are the fields in every user:</p>
  
  <p><a href="https://i.stack.imgur.com/jRSmX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jRSmX.png" alt="These are the fields in every user"></a></p>
  
  <p>Below is the code for search profile:</p>
  
  <pre><code>public class Search_fragment extends Fragment {
  
      private SwipeRefreshLayout mSwipeRefreshLayout;
      DatabaseReference databaseReference;
      Firebase firebase;
     // List&lt;User&gt; list = new ArrayList&lt;User&gt;();
      RecyclerView recyclerView;
      Boolean isScrolling = false;
      Context context;
      FirebaseAuth mAuth;
  
      Button filter;
      FirebaseRecyclerPagingAdapter&lt;User, UserViewHolder&gt; adapter;
      User user10=new User();
      FirebaseUser firebaseUser;
  
      public Search_fragment() {
      }
  
      @Nullable
      @Override
      public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
  
          final View view =  inflater.inflate(R.layout.search__profile, container, false);
  
          ((AppCompatActivity) getActivity()).getSupportActionBar().hide();
  
          String authgender=user10.getGender();
  
  
          filter=(Button)view.findViewById(R.id.button9);
          filter.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Intent it=new Intent(getActivity(),FilterMain.class);
                  startActivity(it);
              }
          });
  
          mSwipeRefreshLayout =view.findViewById(R.id.swipe_refresh_layout);
          recyclerView = (RecyclerView)view.findViewById(R.id.recycler_view);
          recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
  
  
          databaseReference = FirebaseDatabase.getInstance().getReference().child("User");
          PagedList.Config config = new PagedList.Config.Builder()
                  .setEnablePlaceholders(false)
                  .setPrefetchDistance(2)
                  .setPageSize(1)
                  .build();
  
  
          DatabasePagingOptions&lt;User&gt; options = new DatabasePagingOptions.Builder&lt;User&gt;()
                  .setLifecycleOwner(this)
                  .setQuery(databaseReference, config, User.class)
                  .build();
  
          adapter = new FirebaseRecyclerPagingAdapter&lt;User, UserViewHolder&gt;(options) {
              @NonNull
              @Override
              public UserViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
                  return new UserViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler, parent, false),context) {
                  };
              }
              @Override
              protected void onBindViewHolder(@NonNull final UserViewHolder viewHolder, final int i, @NonNull final User user) {
  
                  viewHolder.setItem(user, i);
  
  
                  int newPosition = viewHolder.getAdapterPosition();
  
              }
              @Override
              protected void onLoadingStateChanged(@NonNull LoadingState state) {
                  switch (state) {
                      case LOADING_INITIAL:
                      case LOADING_MORE:
                          // Do your loading animation
                          mSwipeRefreshLayout.setRefreshing(true);
                          break;
  
                      case LOADED:
                          // Stop Animation
                          mSwipeRefreshLayout.setRefreshing(false);
                          break;
  
                      case FINISHED:
                          //Reached end of Data set
                          mSwipeRefreshLayout.setRefreshing(false);
                          break;
  
                      case ERROR:
                          retry();
                          break;
                  }
              }
              @Override
              protected void onError(@NonNull DatabaseError databaseError) {
                  super.onError(databaseError);
                  mSwipeRefreshLayout.setRefreshing(false);
                  databaseError.toException().printStackTrace();
                  // Handle Error
                  retry();
              }
          };
          recyclerView.setAdapter(adapter);
          mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
              @Override
              public void onRefresh() {
                  adapter.refresh();
              }
          });
  return view;
      }
  }
  </code></pre>
  
  <p>Below is code for UserViewHolder:</p>
  
  <pre><code>class UserViewHolder extends RecyclerView.ViewHolder {
  
      DatabaseReference databaseReference;
      Firebase firebase;
      FirebaseAuth mAuth;
      List&lt;User&gt; MainImageUploadInfoList;
      ImageView imageView,invite;
      CircleImageView shortlist;
      public TextView FirstNameTextView;
      public TextView DateTextView;
      public TextView HeightTextView;
      public TextView EducationTextView;
      public TextView OccupationTextView;
      public TextView UserIDTextView;
      public Button send_invitation,shortlist_profile;
      public TextView income;
      public TextView city_state;
      public TextView hobbies;
      public TextView marital_status;
      public TextView family_members;
      public TextView mothers_name;
      public TextView fathers_name;
      public TextView fathers_occupation;
      public TextView mothers_occupation;
      public TextView gendertv;
      public CardView mCardView;
      String sluidgl,sluidtemp;
      public List&lt;User&gt; mUploads;
      int flag=0;
      HashSet&lt;String&gt; set=new HashSet&lt;String&gt;();
  
      User user=new User();
      private final Context context;
      // private Object Context;
  
      public UserViewHolder(@NonNull final View itemView, final Context context) {
          super(itemView);
          this.context=context;
  
          itemView.setTag(user.getUser_id());
          mCardView = (CardView) itemView.findViewById(R.id.cardview1);
          FirstNameTextView = (TextView) itemView.findViewById(R.id.textView1);
          DateTextView = (TextView) itemView.findViewById(R.id.textView3);
          HeightTextView = (TextView) itemView.findViewById(R.id.textView4);
          EducationTextView = (TextView) itemView.findViewById(R.id.textView5);
          OccupationTextView = (TextView) itemView.findViewById(R.id.textView6);
          UserIDTextView = (TextView) itemView.findViewById(R.id.textView7);
          income = (TextView) itemView.findViewById(R.id.income);
          city_state = (TextView) itemView.findViewById(R.id.city_state);
          hobbies = (TextView) itemView.findViewById(R.id.hobbies);
          marital_status = (TextView) itemView.findViewById(R.id.marital_status);
          family_members = (TextView) itemView.findViewById(R.id.family_members);
          mothers_name = (TextView) itemView.findViewById(R.id.mothers_name);
          fathers_name = (TextView) itemView.findViewById(R.id.fathers_name);
          fathers_occupation = (TextView) itemView.findViewById(R.id.fathers_occupation);
          mothers_occupation = (TextView) itemView.findViewById(R.id.mothers_occupation);
          gendertv = (TextView) itemView.findViewById(R.id.gender);
          imageView=(ImageView)itemView.findViewById(R.id.imageView2);
          shortlist=(CircleImageView)itemView.findViewById(R.id.shortlisted);
          invite=(ImageView)itemView.findViewById(R.id.invite);
  
   mCardView.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  int i = (int) itemView.getTag();
  
                  for(i=0;i&lt;=0;i++){
                      final Intent it = new Intent(v.getContext(), ViewProfile.class);
                      it.putExtra("first_name", FirstNameTextView.getText().toString());
                      it.putExtra("date", DateTextView.getText().toString());
                      it.putExtra("height", HeightTextView.getText().toString());
                      it.putExtra("city_state", city_state.getText().toString());
                      it.putExtra("hobbies", hobbies.getText().toString());
                      it.putExtra("highest_education", EducationTextView.getText().toString());
                      it.putExtra("occupation", OccupationTextView.getText().toString());
                      it.putExtra("income", income.getText().toString());
                      it.putExtra("marital_status", marital_status.getText().toString());
                      it.putExtra("family_members", family_members.getText().toString());
                      it.putExtra("fathers_name", fathers_name.getText().toString());
                      it.putExtra("mothers_name", mothers_name.getText().toString());
                      it.putExtra("fathers_occupation", fathers_occupation.getText().toString());
                      it.putExtra("mothers_occupation", mothers_occupation.getText().toString());
                      it.putExtra("user_id", UserIDTextView.getText().toString());
                      imageView.buildDrawingCache();
                      Bitmap bitmap = imageView.getDrawingCache();
                      it.putExtra("profile_image",bitmap);
                      it.putExtra("positionGroup", i);
                      itemView.getContext().startActivity(it);
                  }
              }
          });
      }
      public void setItem(final User user, final int i){
  mCardView.setTag(i);
                      FirstNameTextView.setText(user.getFirst_name() + " " + user.getLast_name());
                      DateTextView.setText(user.getDate());
                      HeightTextView.setText(user.getHeight());
                      EducationTextView.setText(user.getHighest_education());
                      OccupationTextView.setText(user.getOccupation());
                      UserIDTextView.setText(user.getUser_id());
                      income.setText(user.getIncome());
                      city_state.setText(user.getCity_state());
                      hobbies.setText(user.getHobbies());
                      marital_status.setText(user.getMarital_status());
                      family_members.setText(user.getFamily_members());
                      mothers_name.setText(user.getMothers_name());
                      fathers_name.setText(user.getFathers_name());
                      fathers_occupation.setText(user.getFathers_occupation());
                      mothers_occupation.setText(user.getMothers_occupation());
                      gendertv.setText(user.getGender());
                      Picasso.get().load(user.getMainImage()).placeholder(R.mipmap.ic_launcher).fit().into(imageView);
    }
  }
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <pre><code>W/PersistentConnection: pc_0 - Using an unspecified index. Your data will be downloaded and filtered on the client. Consider adding '".indexOn": "gender"' at User/User to your security and Firebase Database rules for better performance
  W/System.err: com.google.firebase.database.DatabaseException: Firebase Database error: Data not found at given child path!
          at com.google.firebase.database.DatabaseError.toException(com.google.firebase:firebase-database@@19.2.1:229)
  W/System.err:     at accentra.in.Search_fragment$2.onError(Search_fragment.java:142)
          at com.shreyaspatil.firebase.recyclerpagination.FirebaseRecyclerPagingAdapter$4.onChanged(FirebaseRecyclerPagingAdapter.java:76)
  W/System.err:     at com.shreyaspatil.firebase.recyclerpagination.FirebaseRecyclerPagingAdapter$4.onChanged(FirebaseRecyclerPagingAdapter.java:73)
          at androidx.lifecycle.LiveData.considerNotify(LiveData.java:131)
          at androidx.lifecycle.LiveData.dispatchingValue(LiveData.java:149)
  W/System.err:     at androidx.lifecycle.LiveData.setValue(LiveData.java:307)
          at androidx.lifecycle.MutableLiveData.setValue(MutableLiveData.java:50)
  W/System.err:     at androidx.lifecycle.Transformations$2$1.onChanged(Transformations.java:155)
          at androidx.lifecycle.MediatorLiveData$Source.onChanged(MediatorLiveData.java:152)
          at androidx.lifecycle.LiveData.considerNotify(LiveData.java:131)
  W/System.err:     at androidx.lifecycle.LiveData.dispatchingValue(LiveData.java:149)
          at androidx.lifecycle.LiveData.setValue(LiveData.java:307)
  W/System.err:     at androidx.lifecycle.MutableLiveData.setValue(MutableLiveData.java:50)
          at androidx.lifecycle.LiveData$1.run(LiveData.java:91)
          at android.os.Handler.handleCallback(Handler.java:794)
  W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:99)
          at android.os.Looper.loop(Looper.java:176)
          at android.app.ActivityThread.main(ActivityThread.java:6662)
          at java.lang.reflect.Method.invoke(Native Method)
  W/System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
  W/FirebaseDataSource: retry() not valid when in state: LOADING_INITIAL
  </code></pre>