//Filter |
|
private fun filter(text: String) { |
|
// creating a new array list to filter our data. |
|
val filteredlist: ArrayList<Lab> = ArrayList() |
|
|
|
// running a for loop to compare elements. |
|
|
|
for (item in itemList) { |
|
// checking if the entered string matched with any item of our recycler view. |
|
if (item.lab_name.lowercase().contains(text.lowercase())) { |
|
// if the item is matched we are |
|
// adding it to our filtered list. |
|
filteredlist.add(item) |
|
} |
|
} |
|
if (filteredlist.isEmpty()) { |
|
// if no item is added in filtered list we are |
|
// displaying a toast message as no data found. |
|
//Toast.makeText(this, "No Data Found..", Toast.LENGTH_SHORT).show() |
|
labAdapter.filterList(filteredlist) |
|
} else { |
|
// at last we are passing that filtered |
|
// list to our adapter class. |
|
labAdapter.filterList(filteredlist) |
|
} |
|
} |