Android中简单实现Spinner的数据绑定

Android中简单实现Spinner的数据绑定

然后声明对象实例并加入到arraylist里面,并设置spinner的适配器

Spinner Sp = (Spinner).............//

List<CItem > lst = new ArrayList<CItem>();

CItem ct = new CItem ("1","测试");

lst.Add(ct);;

ArrayAdapter<CItem > Adapter = new ArrayAdapter<CItem>(context,

android.R.layout.simple_spinner_item, lst);

Sp.SetAdapter(Adapter);

取值:

如果取TEXT值则可以直接取:Sp.getSelectedItem.ToString()或者:((CItem)Sp.getSelectedItem). GetValue() ;

如果取Value值则可以这样取:((CItem)Sp.getSelectedItem).GetID();

java 复制代码
    @Override
    public String toString() {
        // 为什么要重写toString()呢?
        // 因为适配器在显示数据的时候,
        // 如果传入适配器的对象不是字符串的情况下,
        // 直接就使用对象.toString()
        return milktype_name;
    }
相关推荐
Kapaseker2 小时前
我为什么喜欢 Compose ?
android·kotlin
JMchen1232 小时前
【Android 性能优化实战 60 讲】03 Perfetto 现代分析利器:SQL 查询 Trace 数据,微秒级定位函数 CPU 耗时
android·sql·性能优化·实战·源码分析·perfetto·启动优化
开开心心就好3 小时前
手机精确倒计时工具悬浮窗口秒数实时显示
android·前端·javascript·jupyter·智能手机·pdf·html
墨狂之逸才3 小时前
一次 Android 工位机黑屏卡死排查:根因不是 App,而是 scrcpy 与 Rockchip 编码器的 DMA-BUF 泄漏
android·android studio
Privasa-隐私实验室3 小时前
跨端技术选型|Flutter搭建隐私加密App,安卓与iOS双端差异适配实战
android·笔记·安全·flutter·ios·隐私安全·aes-256
limuyang210 小时前
PDF Viewer KMP(基于 chrome 的 PDFium 内核)
android·kotlin
心平气和量大福大14 小时前
android-控件-搜索框SearchView
android·gitee
2601_9621771314 小时前
【MySQL篇】聚合查询,联合查询
android·java·mysql
壮哥_icon14 小时前
【Android】批量 VectorDrawable 动态分别修改 fillColor 和 strokeColor 的踩坑与终极解决方案
android