【发布时间】:2012-05-26 22:49:40
【问题描述】:
我有一个 AlertDialog 的自定义子类,它应该显示范围内所有可用 Wifi 网络的列表。
我通过创建它的实例并调用 show() 来显示此对话框,并且 我没有使用 AlertDialog.Builder(因为我希望使用我的自定义类)。
我有自己的布局来显示为内容视图,但我想要常规的 AlertDialog 外观,带有标题标题和框架。
我的自定义布局非常简单:
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</ListView>
我将它添加到 onCreate() 的对话框中:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle(R.string.pick_wifi_network);
setContentView(R.layout.pick_wifi_dialog);
// Rest of implementation
}
但结果看起来不像 AlertDialog。没有标题,ListView占满整个屏幕:
那么我做错了什么,我应该如何做对呢?
谢谢!
编辑: 为什么我不使用 AlertDialog.Builder:我的自定义 Dialog 类负责监听 WifiManager 的 SCAN_RESULTS_AVALIABLE_ACTION,并在结果刷新时更新 ListView。出于这个原因,我不能使用 AlertDialog.Builder。 结束编辑
【问题讨论】:
-
如果你想要的只是
AlertDialog的默认外观但有一个列表,我不明白你为什么不直接使用AlertDialog.Builder并调用setItems(...)。它将为您创建一个列表。 -
另外,您可以使用
AlertDialog.Builder中的setView()方法来传递自定义布局。 -
我正在编辑我的问题来回答你们俩
标签: java android android-alertdialog android-dialog