Filter List Items By Name, ID

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Filter List Items By Name, ID



I am working on android application that retrieve data from the firebase and show that particular data in list Like This



Now What I have to do is search the items for the list that I have retrieved From Fire base; Apply Search Filter on the basis of Name, Usage and Id.



Here the links and question that I previously studied on Stack Overflow Link1 Link 2 Link3



All of these questions only search on the basis of single Item like name not the multiple Items.



Here is m Adapter class


public class RetreiveActivity extends AppCompatActivity
ListView mylistView;
DatabaseReference db;
SearchView sv;
List<ClassMedicine> medicineList;
@SuppressLint("WrongViewCast")
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_retreive);
mylistView= findViewById(R.id.mylist);
sv= findViewById(R.id.etSearch);
medicineList= new ArrayList<>();
db= FirebaseDatabase.getInstance().getReference("medicines");


@Override
protected void onStart()
super.onStart();
db.addValueEventListener(new ValueEventListener()
@Override
public void onDataChange(DataSnapshot dataSnapshot)
medicineList.clear();
for (DataSnapshot medicineSnapshot:dataSnapshot.getChildren())
ClassMedicine classMedicine=medicineSnapshot.getValue(ClassMedicine.class);
medicineList.add(classMedicine);

MedicineList adapter=new MedicineList(RetreiveActivity.this,medicineList);
mylistView.setAdapter(adapter);

@Override
public void onCancelled(DatabaseError databaseError)

);




Here is my List Layout File


<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:background="@drawable/bgcolor"
android:orientation="vertical"
android:layout_height="match_parent">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="145dp"
android:layout_margin="10dp"
android:background="@drawable/bgcolor">

<TextView
android:id="@+id/tvmediname"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:paddingLeft="15dp"
android:text="Name"
android:textSize="20sp"
tools:ignore="UnknownId" />

<TextView
android:id="@+id/tvmediusage"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/tvmediname"
android:layout_alignStart="@+id/tvmediname"
android:layout_below="@+id/tvmediname"
android:paddingLeft="15dp"
android:text="Usage"
android:textSize="20sp" />

<TextView
android:id="@+id/tvmedigenre"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/tvmediname"
android:layout_alignStart="@+id/tvmediname"
android:layout_below="@+id/tvmediusage"
android:paddingLeft="15dp"
android:text="Company"
android:textSize="20sp" />

<TextView
android:id="@+id/tvexpdate"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/tvmedigenre"
android:paddingLeft="15dp"
android:text="Expiry Date"
android:textSize="20sp" />

<TextView
android:id="@+id/tvmediId"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/tvexpdate"
android:paddingLeft="15dp"
android:text="Medicine Id"
android:textSize="20sp" />

</RelativeLayout>
</LinearLayout>



Here is my Model Class


public class ClassMedicine
String medicineId;
String medicineName;
String medicineUsage;
String medicineGenre;
String mediDate;
public ClassMedicine()



public ClassMedicine(String medicineId, String medicineName, String medicineUsage, String medicineGenre, String mediDate)
this.medicineId = medicineId;
this.medicineName = medicineName;
this.mediDate= mediDate;
this.medicineUsage = medicineUsage;
this.medicineGenre = medicineGenre;


public String getMedicineId()
return medicineId;


public String getMedicineName()
return medicineName;


public String getMedicineUsage()
return medicineUsage;


public String getMedicineGenre()
return medicineGenre;


public String getMediDate() return mediDate;



Here is the XML code of retrieve file


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bgcolor"
android:orientation="vertical"
tools:context="com.example.usmanali.medicineinvent.RetreiveActivity">
<TextView
android:id="@+id/mytext"
style="@style/Base.TextAppearance.AppCompat.Large"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/bggradient"
android:text="@string/my_medicines"
android:textAlignment="center"
android:textSize="25sp"
android:textStyle="italic" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Search"
android:id="@+id/etSearch"
/>

<ListView
android:id="@+id/mylist"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp">
</ListView>
</LinearLayout>









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard