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

发布时间:2026/9/23 13:07:52
卜若的代码笔记-android系列-插件:带图片的Spinner插件 1.该插件是我自己封装了一下提高用户体验具体解释请转以下https://blog.csdn.net/Zaajuan1150/article/details/817048652.插件封装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 MapString, ? data, int resource, String[] from, int[] to) { super(context, data, resource, from, to); ct context; } public static ImageAdapter createImageAdapter(Context ctt,ListMapString, 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 ListMapString,Object mapList new ArrayList(); public static ImageAdapter createImageAdapter(Context ct2){ ListMapString,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){ MapString,Object m2 new HashMapString,Object(); m2.put(text,textValue); m2.put(image,obj); mapList.add(m2); } }3.使用到的资源R.layout.spinner_2_example?xml version1.0 encodingutf-8? LinearLayout xmlns:androidhttp://schemas.android.com/apk/res/android android:layout_widthmatch_parent android:layout_heightwrap_content android:orientationhorizontal android:gravitycenter ImageView android:idid/colorview android:layout_width20dp android:layout_height20dp android:layout_marginLeft10dp android:srcmipmap/ic_launcher / TextView android:idid/textview android:layout_widthmatch_parent android:layout_height40dp android:gravitycenter|left android:paddingLeft10dp android:textSize15dp / /LinearLayout4.调用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; }

关于本文作者

来自尧图内容编辑团队

尧图内容编辑团队 内容团队

尧图内容编辑团队

本文由尧图网络内容编辑团队执笔。团队由资深项目经理、前端工程师与设计师组成,所有内容均来自亲手交付的真实项目,先讲清问题、再给出可落地的解法。尧图深耕北京网站建设十年,服务过京华建材集团、智造科技等各行业客户,把一线经验沉淀为可复用的行业观察。

  • 十年建站经验,覆盖建材、制造、服务、文创等
  • 项目经理把关选题与事实准确性
  • 工程师与设计师联合撰写专业细节
  • 统一编辑规范,保证文风与排版一致
  • 每月复盘转化数据,迭代选题方向

延伸阅读

相关资讯与近期热门内容

深度阅读推荐

建站决策前值得细读的三篇

网站改版的5个关键决策
2024-08-12

网站改版的5个关键决策

什么时候该改版、改到什么程度、如何避免流量掉光,京华建材集团改版复盘给出答案。

获取专属建站方案

看完文章,把您的行业与预算告诉我们,免费获取一份量身定制的官网建设方案与报价。

立即免费咨询