我已經通過膨脹以下XML創建AlertDialog:無法查看按鈕(一個或多個)在充氣視圖
LayoutInflater li = LayoutInflater.from(this);
View dialogView = li.inflate(R.layout.activity_list_logs, null);
ListView list = (ListView) dialogView.findViewById(R.id.listDates);
用於示出alertDialog完整的代碼:
private void showLogs(final List<Absentees> abs) {
LayoutInflater li = LayoutInflater.from(this);
View dialogView = li.inflate(R.layout.activity_list_logs, null);
ListView list = (ListView) dialogView.findViewById(R.id.listDates);
list.setAdapter(new CustomAdapterTagAbsentees(this,abs));
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapter, View view,int position, long id) {
Absentees a =(Absentees)adapter.getItemAtPosition(position);
try
{
showLogDetails(a);
}
catch(Exception e)
{
show_popup(e+"");
}
}
});
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setView(dialogView);
alertDialogBuilder.setTitle("Attendance Details:");
alertDialogBuilder.setMessage("Day : ");
alertDialogBuilder
.setCancelable(true)
.setPositiveButton("Dismiss",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
dialog.cancel();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
的使用的佈局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
>
<ListView
android:id="@+id/listDates"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:textSize="20sp"
/>
</LinearLayout>
關於我的問題:
如果列表足夠小以適應屏幕我可以看到「關閉」按鈕(positiveButton)。
否則,如果列表太大,我無法看到「辭退」按鈕
請幫助我!,我嘗試將按鈕添加到的內底佈局本身,它的顯示正確,但我不知道爲什麼這個默認的顯示positiveButton的方式完全不
'AlertDialog.Builder'早已內部ListView和所述setAdapter方法。只需刪除所有的視圖充氣的東西,並調用'alertDialogBuilder.setAdapter(new,CustomAdapterTagAbsentees(this,abs)' – Blackbelt
@blackbelt這是否適用於自定義適配器? – Shan
當然它確實是 – Blackbelt