设置单选列表只需 AlertDialog.Builder里面的setSingleChoiceItems 来设置即可
实现步骤如下:
第一步:用来显示列表内容的
res/values/array.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <string-array name="hobby"> <item>篮球</item> <item>足球</item> <item>排球</item> </string-array> </resources>
第二步:还是定义一个输入框和一个按钮
res/layout/single_choice_dialog_layout.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content"> <EditText android:id="@+id/editText" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="这是一个单选列表对话框" /> <Button android:id="@+id/button" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="显示单选列表对话框" /> </LinearLayout&

本文详细介绍了如何在Android中创建一个单选列表对话框,包括XML布局文件的定义、DialogInterface.OnClickListener事件处理及自定义类的使用,以实现用户选择列表项并显示在EditText中的功能。
最低0.47元/天 解锁文章
794

被折叠的 条评论
为什么被折叠?



