Android——Adapter

ArrayAdapter

layout/item_select.xml

xml 复制代码
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:gravity="center"
    android:textColor="#0000ff"
    android:textSize="17sp"
    android:text="火星"/>
xml 复制代码
    <Spinner
        android:id="@+id/sp_dropdown"
        android:layout_width="match_parent"
        android:layout_height="19dp"
        android:spinnerMode="dropdown"/>
java 复制代码
	private Spinner sp_dropdown;
    private static final String[] starArray = {"金星", "水星", "木星","地球", "木星", "土星"};
java 复制代码
 	ArrayAdapter<String> starArrayAdapter = new ArrayAdapter<>(this, R.layout.item_select, starArray);
    sp_dropdown.setAdapter(starArrayAdapter);

SimpleAdapter

java 复制代码
    private static final int[] iconArray = {
            R.drawable.shuixing, R.drawable.tuxing,
            R.drawable.muxing, R.drawable.diqiu,
            R.drawable.huoxing, R.drawable.jinxing,
    };
    private static final String[] starArray = {"金星", "水星", "木星", "地球", "木星", "土星"};
java 复制代码
        List<Map<String, Object>> list = new ArrayList<>();

        for (int i = 0; i < iconArray.length; i++) {
            Map<String, Object> item = new HashMap<>();
            item.put("icon", iconArray[i]);
            item.put("name", starArray[i]);

            list.add(item);
        }
        SimpleAdapter starSimpleAdapter = new SimpleAdapter(this, list,
                R.layout.item_simple,
                new String[]{"icon", "name"},
                new int[]{R.id.iv_icon, R.id.tv_name});

        sp_dropdown.setAdapter(starSimpleAdapter);
        sp_dropdown.setSelection(0);
        sp_dropdown.setOnItemSelectedListener(this);

案例代码

相关推荐
三少爷的鞋2 小时前
Repository 方法设计:suspend 与 Flow 的决选择指南(以朋友圈为例)
android
阿里云云原生3 小时前
Android App 崩溃排查指南:阿里云 RUM 如何让你快速从告警到定位根因?
android·java
cmdch20175 小时前
手持机安卓新增推送按钮功能
android
攻城狮20155 小时前
【rk3528/rk3518 android14 kernel-6.10 emcp sdk】
android
何妨呀~5 小时前
mysql 8服务器实验
android·mysql·adb
QuantumLeap丶6 小时前
《Flutter全栈开发实战指南:从零到高级》- 25 -性能优化
android·flutter·ios
木易 士心7 小时前
MVC、MVP 与 MVVM:Android 架构演进之路
android·架构·mvc
百锦再7 小时前
国产数据库的平替亮点——关系型数据库架构适配
android·java·前端·数据库·sql·算法·数据库架构
走在路上的菜鸟7 小时前
Android学Dart学习笔记第十三节 注解
android·笔记·学习·flutter
介一安全8 小时前
【Frida Android】实战篇15:Frida检测与绕过——基于/proc/self/maps的攻防实战
android·网络安全·逆向·安全性测试·frida