0
    
 Làm sao để search ra item là object trong 1 listview
Trang https://www.javatpoint.com/android-searchview có hướng dẫn mình cách search 1 item trong list view. Nhưng trong hướng dẫn của nó listview ấy là dạng thường, mà cái listview của mình là customlistview dạng object class
java code của mình:
{
    ListView listView;
    
    ArrayList<NoteModel> arrayList;
    
    NoteAdapter noteAdapter;
 }
vậy khi sự kiên searchView.setOnQueryTextListener ở dưới mình phải thay đổi thế nào
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {  
        @Override  
        public boolean onQueryTextSubmit(String query) {  
            if(list.contains(query)){  
                adapter.getFilter().filter(query);  
            }else{  
                Toast.makeText(MainActivity.this, "No Match found",Toast.LENGTH_LONG).show();  
            }  
            return false;  
        }  
        @Override  
        public boolean onQueryTextChange(String newText) {  
        //    adapter.getFilter().filter(newText);  
            return false;  
        }  
});
            Thêm một bình luận
         
1 CÂU TRẢ LỜI
        -3
    
 Custom lại Adapter
Theo mình vấn đề của bạn đang gặp phải là ở chỗ filter. Bạn có thể viết thêm một public method vào adapter như này chẳng hạn:
# NodeAdapter
public boolean filterByNodeTitle(String newText) {  
    IList filtered = new List();
    foreach(NodeModel note in this.notes) {
        if (note.title.toString().Contains(newText)) {
            filtered.Add(note);
        }
    }
   this.notes = filtered;
   // Thông báo cho ListView thay đổi:
   NotifyDataSetChanged();
} 
# activity:
public boolean onQueryTextChange(String newText) {  
    adapter.filterByNoteTitle(newText);
} 
Hoặc là bạn có thể custom lại getFilter(), hàm này return ra một instance Filter khác, lớp Filter này có method filter() chính là method filterByNoteTitle() ở trên.
Bạn thử xem nhé, chúc bạn thành công. À mà cá nhân mình lại thích dùng RecyclerView hơn là ListView. hihi
 
  
  
 