【Android】spinner下拉框
程序员文章站
2022-07-14 18:07:51
...
如何使用spinner
1.在xml中写入此控件
<EditText
android:id="@+id/textFrameNoId"
style="@style/style_comm_card_right"
android:visibility="gone" />
<Spinner
android:id="@+id/spinnerBaseFrameNo"
style="@style/style_comm_card_right"
android:clickable="true"
android:focusableInTouchMode="false"
android:hint="--请选择--"
android:spinnerMode="dropdown" />
2.在activity中获得此控件
@ViewInject(R.id.textFrameNoId)
private EditText mFrameNoId;
@ViewInject(R.id.spinnerBaseFrameNo)
private Spinner mBaseFrameNo;
3.在activity中加载view
private void initView() {
setContentView(R.layout.devinfo_register);
ViewUtils.inject(this);
mBaseFrameNo.setOnItemSelectedListener(mBaseFrameNoOnItemSelectedListener);
4.从缓存中获取数据
//从打开app缓存的字典中获取架号、层号、位号的字典
private List<CommBean> mFrameNos = DictProtocol.getInnerDict(DictCacheUtils.getString(this, "DEV_BASE_FRAME_NO"));
5.将数据添加到控件中
private void initDatas() {
CommonDictAdapter mFrameNoAdapter = new CommonDictAdapter(mFrameNos, this);
mBaseFrameNo.setAdapter(mFrameNoAdapter);
6.注意:全部成功后才会显示出下拉框
给spinner赋予默认值
mBaseFrameNo.setSelection(1);
和.setSelection(position, animate)
上一篇: 二叉树的最小、最大深度以及平衡二叉树
下一篇: 力扣2-队列的最大值