1、创建LayoutInflater
LayoutInflater li=LayoutInflater.from(this);
2、填充布局
View quakeDetailsView=li.inflate(R.layout.quake_details, null);
3、创建AlertDialog
AlertDialog.Builder quakeDialog=new AlertDialog.Builder(this);AlertDialog的构造函数都是protect的,android只提供了AlertDialog.Builder来构造AlertDialog
4、设置AlertDialog自定义视图
quakeDialog.setView(quakeDetailsView);
5、返回Dialog
quakeDialog.create();
LayoutInflater li
=
LayoutInflater.from(
this
);
// 将R.layout.quake_details填充到Layout
View quakeDetailsView = li.inflate(R.layout.quake_details, null );
// 创建AlertDialog,AlertDialog只能通过AlertDialog.Builder创建
AlertDialog.Builder quakeDialog = new AlertDialog.Builder( this );
// 指定R.layout.quake_details为Dialog的View
quakeDialog.setView(quakeDetailsView);
return quakeDialog.create();
// 将R.layout.quake_details填充到Layout
View quakeDetailsView = li.inflate(R.layout.quake_details, null );
// 创建AlertDialog,AlertDialog只能通过AlertDialog.Builder创建
AlertDialog.Builder quakeDialog = new AlertDialog.Builder( this );
// 指定R.layout.quake_details为Dialog的View
quakeDialog.setView(quakeDetailsView);
return quakeDialog.create();