Question: How to filter RecyclerView by multiple fields using Android studio java Please help activate the button as required and write the full code Mian layout
How to filter RecyclerView by multiple fields using Android studio java
Please help activate the button as required and write the full code
Mian layout
Mian java code
package com.example.luqya;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.osBundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.widget.LinearLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.SearchView;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.util.ArrayList;
import java.util.List;
public class Events extends AppCompatActivity
private LinearLayout profileBtn homeBtnhomeBtn;
private FirebaseAuth authProfile;
List dataList;
DatabaseReference databaseReference;
ValueEventListener eventListener;
RecyclerView recyclerView;
public static int sid;
public SharedPreferences settings;
SearchView searchView;
MyAdapter adapter;
@SuppressLintMissingInflatedId
@Override
protected void onCreate@Nullable Bundle savedInstanceState
super.onCreatesavedInstanceState;
setContentViewRlayout.activityevents;
getWindowsetSoftInputModeWindowManagerLayoutParams.SOFTINPUTADJUSTPAN;
profileBtn findViewByIdRidProfileBtn;
homeBtn findViewByIdRidHomeBtn;
homeBtn findViewByIdRidhomeBtn;
authProfile FirebaseAuth.getInstance;
FirebaseUser firebaseUser authProfile.getCurrentUser;
settings getSharedPreferencesID;
sid settings.getIntid;
searchView findViewByIdRideditTextSearch;
searchView.clearFocus;
recyclerView findViewByIdRidrecyclerView;
GridLayoutManager gridLayoutManager new GridLayoutManagerEventsthis, ;
recyclerView.setLayoutManagergridLayoutManager;
RecyclerView.LayoutManager layoutManager new LinearLayoutManagerEventsthis, LinearLayoutManager.HORIZONTAL, false;
recyclerView.setLayoutManagerlayoutManager;
AlertDialog.Builder builder new AlertDialog.BuilderEventsthis;
builder.setCancelablefalse;
builder.setViewRlayout.progresslayout;
AlertDialog dialog builder.create;
dialog.show;
dataList new ArrayList;
adapter new MyAdapterEventsthis, dataList;
recyclerView.setAdapteradapter;
databaseReference FirebaseDatabase.getInstancegetReferenceAdd Event";
dialog.show;
eventListener databaseReference.addValueEventListenernew ValueEventListener
@Override
public void onDataChange@NonNull DataSnapshot snapshot
dataList.clear;
for DataSnapshot itemSnapshot : snapshot.getChildren
DataClass dataClass itemSnapshot.getValueDataClassclass;
dataList.adddataClass;
adapter.notifyDataSetChanged;
dialog.dismiss;
@Override
public void onCancelled@NonNull DatabaseError error
dialog.dismiss;
;
searchView.setOnQueryTextListenernew SearchView.OnQueryTextListener
@Override
public boolean onQueryTextSubmitString query
return false;
@Override
public boolean onQueryTextChangeString newText
searchListnewText;
return true;
;
profileBtnsetOnClickListenernew View.OnClickListener
@Override
public void onClickView view
if firebaseUser null
Intent i new IntentEventsthis, LogIn.class;
startActivityi;
else
Intent i new IntentEventsthis, ShowSeekerProfile.class;
startActivityi;
;
homeBtnsetOnClickListenernew View.OnClickListener
@Override
public void onClickView view
Intent i new IntentEventsthis, Events.class;
startActivityi;
;
homeBtnsetOnClickListenernew View.OnClickListener
@Override
public void onClickView view
Intent i new IntentEventsthis, MyEventbar.class;
startActivityi;
;
@Override
public boolean onCreateOptionsMenuMenu menu
Inflate the menu; this adds items to the action bar if it is present.
getMenuInflaterinflateRmenu.menuprofileseeker, menu;
return true;
@Override
public boolean onOptionsItemSelected@NonNull MenuItem item
int id item.getItemId;
if id Ridactioneditprofile
Intent goeditprofile new IntentgetApplicationContext EditSeekerProfile.class;
goeditprofile.putExtrastdidsid;
startActivitygoeditprofile;
else if id Ridactionlogout
getSharedPreferencesIDeditclearcommit;
Intent gologin new IntentgetApplicationContextLogIn.class;
startActivitygologin;
return super.onOptionsItemSelecteditem;
public void searchListString text
ArrayList searchList new ArrayList;
for DataClass dataClass: dataList
if dataClassgetNametoLowerCasecontainstexttoLowerCase
searchList.adddataClass;
adapter.searchDataListsearchList;
@Override
protected void onResume
super.onResume;
searchView.clearFocus; Clear focus from the SearchView
Optionally request focus on a different view:
anotherView.requestFocus;
Filter layout
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
