I saved the large data from server to array list,I am doing search the list using custom array list like: Arraylist
Normally i did like: 1. Add one Edit text and apply TextWatcher listner to fire filter method. 2. I design one simple filter method and filter some data and pass list to the adapter
I know data is too large but i don't know another method.
My filter method is:
override fun doInBackground(vararg params: String): String {
if (charString.isEmpty()) {
menu_list_filtered = arrayListOf()
} else {
val filteredList = ArrayList<MenuListItem>()
var i =0
while (i < menu_list.size && !isCancelled()) {
loge(TAG,"is p canceled "+isCancelled)
val arrayList = ArrayList<ProductListItem>()
var j =0
while (j < 2 && !isCancelled()) {
loge(TAG,"is c canceled "+isCancelled)
if(menu_list.get(i).product_list!![j].p_name.toLowerCase().contains(charString.toLowerCase()) || menu_list.get(i).product_list!![j].p_desc.toLowerCase().contains(charString.toLowerCase())){
arrayList.add(ProductListItem("","", arrayListOf(), menu_list.get(i).product_list!![j].p_desc,"","", menu_list.get(i).product_list!![j].p_name,"","","","",""))
filteredList.add(MenuListItem("","","","", menu_list.get(i).c_name,arrayList))
}
++j
}
++i
}
menu_list_filtered = filteredList
}
}
finally i am passing menu_list_filtered to adapter and set notifydatasetchanged()
Problem: When i enter one character on edit text, my UI (focus on edit text) getting stuck a while, I don't know the problem it is getting so much of time I tried Asyntask but not resolved. I know it may be reason of contain list which is so large but i don't know another option. please suggest me how can i filter(locally) smooth in my project.