当前位置: 首页 > news >正文

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

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; }
http://www.jsqmd.com/news/1281650/

相关文章:

  • AI 周报 — 2026 年第 31 周(7 月 20 日 — 7 月 26 日)
  • 数字体系中的“无”:论绝对控制的伪命题与多元解读的生命力
  • 无锡钢结构拆除回收公司哪家好,上门收废品公司推荐|君东环保口碑推荐 - geo88
  • 图数据结构与算法实战:从基础到工程优化
  • ClosedXML终极指南:快速掌握.NET Excel处理的完整解决方案
  • 免登录调用DeepSeek Web API实现代码生成:浏览器开发者工具实战指南
  • Maven 创建 Spring、SpringMVC、Mybatis(SSM)项目
  • 四层板分层架构与平面分割底层原理
  • 免费微信投票制作教程:选手批量导入、投票数据导出操作指南 - 微信投票小程序
  • Anthropic联手Cognizant 企业AI落地比想象中难
  • 基于Windows音频API的麦克风静音控制技术:MicMute架构设计与实现原理
  • 网易后端面试全解析:从211本科到一线大厂的实战指南
  • 为什么你的AI副业总在加班?:4类时间伪勤奋诊断表+实时监控SOP,今晚就能启用
  • SpringBoot+Vue景区订票系统适老化设计与实现
  • 20 高凹凸型排(蓄)水板生产企业推荐指南(2026 招投标完整版) - 排水板厂家
  • 华为USG防火墙HRP双机查看命令
  • 工业电容器故障诊断与预防维护全攻略
  • QQ空间说说备份神器GetQzonehistory:3步永久保存青春记忆
  • 为什么92%的AI选手在Phase 2崩溃?——基于2020–2024年17场国际AI赛事数据的失败归因模型
  • 5分钟掌握raylib:零依赖跨平台游戏开发的终极入门指南
  • 四层板电源层标准化分割实操全流程方案
  • 物联网设备安全:SE050与PIC18F4525硬件集成方案
  • Nmap NSE脚本实战:从端口扫描到漏洞检测的进阶指南
  • 杭州管道疏通避坑指南 2026年临平区业主真实推荐 - 余生黄金回收
  • NVIDIA发起开放安全AI联盟 闭源真的更安全吗
  • 耐根穿刺型高分子异型片自粘土工布生产企业推荐指南(2026 招投标完整版) - 排水板厂家
  • Linux命令-sh(Bourne Shell 与 POSIX 模式 Shell)
  • MyBatis注解之一对多关联实战
  • 开源模型本地部署不是“复制粘贴”!资深MLOps工程师拆解7层依赖链:Python环境、CUDA驱动、量化格式、Tokenizer对齐、KV Cache优化…
  • 数据库的相关概念