[英]Android Studio: Searchview for images, how?
I have a Gridview with Images on it, and a search bar on the top of my page. 我有一个带有图像的Gridview,并且在页面顶部有一个搜索栏。 I know how to use the search bar to filter text, but how can I filter images?
我知道如何使用搜索栏来过滤文本,但是如何过滤图像? Is there a way to somehow "tag" the images?
有没有办法以某种方式“标记”图像?
Thanks! 谢谢!
You must create a data model for your images and use an id
to filter them. 您必须为图像创建数据模型,并使用
id
进行过滤。
public class MyDataModel {
int resourceId;
String imageName
public MyDataModel(String name, resourceId);
// constructors getters, setters, etc
}
And in your activity you can create a list with your data: 在您的活动中,您可以创建一个包含数据的列表:
List<MyDataModel> data = new List();
data.add(new MyDataModel("name", R.drawable.name))
//import all your data
And then on your SearchView
query listener add to filter to Adapter
; 然后在您的
SearchView
查询侦听器上添加以过滤到Adapter
;
adapter.getFilter().filter(//name);
Create a list of names of images and for each item of the adapter you tag the names of the images. 创建图像名称列表,并为适配器的每个项目标记图像名称。 Now filter the adapter using the tags of the images.
现在,使用图像的标签过滤适配器。 :)
:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.