My RecyclerView is working properly with one model class and custom adapter since my data comes from the Firebase Realtime Database. But now I would like to filter the adapter with a spinner menu. Like when the user selects an item from the menu the RecyclerView will be filtered and only it will show the item which is similar to the selected item. So how can I implement this?
public class Doctor extends AppCompatActivity {
RecyclerView recyclerView2;
myAdapter2 adapter2;
@SuppressLint("ResourceType")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_doctor);
recyclerView2=findViewById(R.id.recylerView2);
recyclerView2.setLayoutManager(new LinearLayoutManager(this));
FirebaseRecyclerOptions<model2> options =
new FirebaseRecyclerOptions.Builder<model2>()
.setQuery(FirebaseDatabase.getInstance().getReference().child("Doctor_list"), model2.class)
.build();
adapter2=new myAdapter2(options);
recyclerView2.setAdapter(adapter2);
}
@Override
protected void onStart() {
super.onStart();
adapter2.startListening();
}
@Override
protected void onStop() {
super.onStop();
adapter2.stopListening();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.spinnermenu,menu);
return super.onCreateOptionsMenu(menu);
}
}
Here is my custom menu
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/medicine"
android:title="Medicine"
app:showAsAction="never">
</item>
<item
android:id="@+id/phycology"
android:title="Phycology"
app:showAsAction="never">
</item>
<item
android:id="@+id/orthopedic"
android:title="Orthopedic"
app:showAsAction="never">
</item>
</menu>