ArrayAdapter
layout/item_select.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="火星"/>
<Spinner
android:id="@+id/sp_dropdown"
android:layout_width="match_parent"
android:layout_height="19dp"
android:spinnerMode="dropdown"/>
private Spinner sp_dropdown;
private static final String[] starArray = {"金星", "水星", "木星","地球", "木星", "土星"};
ArrayAdapter<String> starArrayAdapter = new ArrayAdapter<>(this, R.layout.item_select, starArray);
sp_dropdown.setAdapter(starArrayAdapter);
SimpleAdapter
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 = {"金星", "水星", "木星", "地球", "木星", "土星"};
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);