尧图网站建设 尧图网络
  • 首页
  • 关于我们
  • 服务项目
  • 案例展示
  • 建站流程
  • 资讯中心
  • 联系我们
首页/资讯中心/详情

卜若的代码笔记-android系列-插件:带图片的Spinner插件

卜若的代码笔记-android系列-插件:带图片的Spinner插件
📅 发布时间:2026/7/28 16:29:41

1.该插件是我自己封装了一下,提高用户体验,具体解释请转以下:

https://blog.csdn.net/Zaajuan1150/article/details/81704865

2.插件封装:

package com.draw.depp.deeplearningdrawer.Plugins.ImageSpinnerPlugins; import android.content.Context; import android.view.View; import android.widget.AdapterView; import android.widget.SimpleAdapter; import android.widget.Spinner; import com.draw.depp.deeplearningdrawer.R; import com.draw.depp.deeplearningdrawer.Tool.CarColorUtil; import com.draw.depp.deeplearningdrawer.Tool.Debug; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class ImageAdapter extends SimpleAdapter { public Context ct; public ImageAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to) { super(context, data, resource, from, to); ct = context; } public static ImageAdapter createImageAdapter(Context ctt,List<Map<String, Object>> dataMap){ ImageAdapter adp = new ImageAdapter(ctt, dataMap, R.layout.spinner_2_example, new String[] { "image", "text" }, new int[] {R.id.colorview, R.id.textview }); return adp; } public static List<Map<String,Object>> mapList = new ArrayList<>(); public static ImageAdapter createImageAdapter(Context ct2){ List<Map<String,Object>> l2 = new ArrayList<>(); for (Map k: mapList ) { l2.add(k); } mapList.clear(); ImageAdapter i2 = createImageAdapter(ct2,l2); return i2; } public static void addSpinner(String textValue,Object obj){ Map<String,Object> m2 = new HashMap<String,Object>(); m2.put("text",textValue); m2.put("image",obj); mapList.add(m2); } }

3.使用到的资源:R.layout.spinner_2_example

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:gravity="center"> <ImageView android:id="@+id/colorview" android:layout_width="20dp" android:layout_height="20dp" android:layout_marginLeft="10dp" android:src="@mipmap/ic_launcher" /> <TextView android:id="@+id/textview" android:layout_width="match_parent" android:layout_height="40dp" android:gravity="center|left" android:paddingLeft="10dp" android:textSize="15dp" /> </LinearLayout>

4.调用:

Spinner spinner = findViewById(R.id.type); ImageAdapter.addSpinner("广州",R.mipmap.ic_launcher); ImageAdapter.addSpinner("贵阳",R.mipmap.ic_launcher); ImageAdapter.addSpinner("华西",R.mipmap.ic_launcher); ImageAdapter adp = ImageAdapter.createImageAdapter(MainActivity.this); spinner.setAdapter(adp);

5.预览:

6.关于怎么抽出text的值,一个自写解析器:

package com.draw.depp.deeplearningdrawer.Plugins.ImageSpinnerPlugins; public class ImageAdapterAnalyser { public String analyserValue = ""; public String[] analyserList ; public String text; public String image; public ImageAdapterAnalyser(String key){ this.analyserValue = key; char[] charArray = new char[key.length() - 2]; int index = 0; for (char a : analyserValue.toCharArray()){ if (a== '{'){ continue; } if(a == '}'){ continue; } charArray[index] = a; index++; } analyserValue = new String(charArray); analyserList = analyserValue.split(","); image = analyserList[0].split("=")[1].trim(); text = analyserList[1].split("=")[1].trim(); } }

7.解析调用:

spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { String content = parent.getItemAtPosition(position).toString(); Debug.Log(new ImageAdapterAnalyser(content).text); type = content; }

相关新闻

  • 图数据结构与算法实战:从基础到工程优化
  • Anthropic联手Cognizant 企业AI落地比想象中难
  • 5分钟掌握raylib:零依赖跨平台游戏开发的终极入门指南

最新新闻

  • LangChain对话上下文管理:原理与实践指南
  • 2026年东莞除甲醛行业深度观察:三大口碑品牌对比 - 环保除醛知识库
  • 泉州除甲醛优选名单:绿舒环保等6家深度测评 - 绿舒环保母婴除甲醛
  • 2026工业清洗剂与脱脂剂厂家推荐盘点:脱脂剂与工业清洗剂厂家推荐清单及选型指南甄选洛合新材料 - 栗子测评
  • 终极游戏音频提取指南:acbDecrypter让你的游戏音乐轻松解密转换
  • 数据结构实验(C语言):图(邻接矩阵表示及输出)

日新闻

  • 力旷智能:伺服驱动系统在制药收瓶设备中的应用解析
  • 2026 网安入门避坑指南,零基础如何避开无效学习直接上手实战
  • 揭秘CFC项目:如何通过手机摄像头实现850kbps无网络文件传输

周新闻

  • 大连理工大学与东京大学联手打造的“主动型AI助手“
  • 170.2026年国家级科研瓶颈:超精密单点金刚石切削(SPDT)光学表面生成
  • SongBloom:革命性歌曲生成框架深度解析——如何通过交织自回归与扩散模型创作完整音乐

月新闻

  • 2026年6月公司网站搭建最新热门渠道测评:四大低成本/零代码平台对比+避坑
  • 【Linux】Linux arm 编译QT程序,出现expected “}“报错
  • 【MATLAB例程】四基站二维AOA定位与距离辅助增强对比仿真。基于角度观测和测距修正的固定目标平面定位精度分析

关于尧图

  • 公司简介
  • 团队介绍
  • 企业文化
  • 荣誉资质

服务项目

  • 定制开发
  • 电商建站
  • UI 设计
  • 运维服务

快速链接

  • 案例展示
  • 建站流程
  • 常见问题
  • 资讯中心

联系方式

  • 📍北京市朝阳区互联网产业园 A 座 10 层
  • 📞400-888-8888
  • ✉️contact@rkmt.cn
  • 🕐周一至周日 9:00-21:00

© 2024 北京尧图网络科技有限公司 版权所有 | 京 ICP 备 XXXXXXXX 号