1

I am having an issue, I wrote the code for the RecyclerView, but I cannot find anywhere how to create a FilterView. So it's basically, the user will write something in the EditText, name or ID, and then the user will click on a button called "bsearch", after that the new Filtered view will be displayed, but I've tried so many ways, and I can't seem to get my head around it.

public class ExistingPatient extends AppCompatActivity {

    private ListView ListView;
    private FirebaseListAdapter adapter;

    EditText search_patient;
    ImageButton bsearch;
    private DatabaseReference mDatabase;

    private FirebaseRecyclerAdapter<Patient,ExistingPatient.PatientViewHolder> mPatientAdapter;
    private RecyclerView RView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_existing_patient2);
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
        search_patient = (EditText) findViewById(R.id.search_patient);

        ListView = (ListView) findViewById(R.id.ListView);

        bsearch = (ImageButton) findViewById(R.id.bCamera2);

        setTitle("Patients");

        mDatabase = FirebaseDatabase.getInstance().getReference("Patients");
        mDatabase.keepSynced(true);

        RView = (RecyclerView) findViewById(R.id.RView);
        Query patientQuery = mDatabase.orderByKey();

        RView.setLayoutManager(new LinearLayoutManager(this));

        FirebaseRecyclerOptions patientOptions = new FirebaseRecyclerOptions.Builder<Patient>().setQuery(patientQuery, Patient.class).build();

        mPatientAdapter = new FirebaseRecyclerAdapter<Patient, ExistingPatient.PatientViewHolder>(patientOptions) {
            @Override
            protected void onBindViewHolder(ExistingPatient.PatientViewHolder holder, final int position, final Patient model) {
                holder.setName("Name: " + model.getName());
                holder.setAge("Age: " + model.getAge());
                holder.setDOB("DOB:" + model.getDOB());
                holder.setID("ID: " + model.getID());
                holder.setSymptoms("Symptoms: " + model.getSymptoms());

                holder.mView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        final String name = model.getName();
                        final String age = model.getAge();
                        final String dob = model.getDOB();
                        final String id = model.getID();
                        final String symptoms = model.getSymptoms();
                        Intent intent = new Intent(getApplicationContext(), PatientInformation.class);
                        intent.putExtra("id", id);
                        intent.putExtra("name", name);
                        intent.putExtra("age", age);
                        intent.putExtra("dob", dob);
                        intent.putExtra("symptoms", symptoms);
                        startActivity(intent);
                    }
                });
            }


            @Override
            public ExistingPatient.PatientViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

                View view = LayoutInflater.from(parent.getContext())
                        .inflate(R.layout.item_patient, parent, false);

                return new ExistingPatient.PatientViewHolder(view);
            }
        };

        RView.setAdapter(mPatientAdapter);
    }

How should I go on from here? Thank you.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Peter Aoun
  • 19
  • 3
  • Have a look at this: https://stackoverflow.com/questions/48061546/android-firebase-searching-with-filtering/48062439#48062439 – mark922 Jun 29 '18 at 06:22

0 Answers0