简体   繁体   English

Android Studio:Searchview中的图像,如何?

[英]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.

相关问题 将 SearchView 与 ArrayList Android Studio 一起使用 - Using SearchView with ArrayList Android Studio "<i>How to dismiss keyboard after pressing the &quot;X&quot; in searchview?<\/i>在搜索视图中按“X”后如何关闭键盘?<\/b> <i>(Android Studio Java)<\/i> (Android 工作室 Java)<\/b>" - How to dismiss keyboard after pressing the "X" in searchview? (Android Studio Java) 如何在Android中实现SearchView - How to implement a SearchView in Android 使用SearchView android studio在工具栏中留下空间 - Left space in Toolbar with SearchView android studio 如何在android中实现searchview过滤器? - how to implement searchview filter in android? Android Studio:SearchView:searchView.setSearchableInfo(searchManager.getSearchableInfo(cn))中的错误; - Android Studio: SearchView: error in searchView.setSearchableInfo(searchManager.getSearchableInfo(cn)); 如何在Android Studio中将RadioButton与图像链接 - How to link RadioButtons with images in Android Studio 如何在 Android Studio 中显示高分辨率的图像? - How to show images with a high resolution in Android Studio? 如何在 android studio 上添加用户图片? - How to do user added images on android studio? 如何在 Android Studio 中将文本设置为对应的图像 - How to set text to corresponding images in Android Studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM