我有一个 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。 结束编辑