LayoutInflater inflater = getLayoutInflater(); View view = inflater.inflate(R.layout.my_layout, null);
ViewGroup container = findViewById(R.id.container); LayoutInflater inflater = getLayoutInflater(); View view = inflater.inflate(R.layout.my_layout, container, false);
AlertDialog.Builder builder = new AlertDialog.Builder(this); LayoutInflater inflater = getLayoutInflater(); View dialogView = inflater.inflate(R.layout.dialog_layout, null); builder.setView(dialogView).setTitle("My Dialog"); AlertDialog dialog = builder.create(); dialog.show();In this example, the getLayoutInflater() method is called to retrieve an instance of the LayoutInflater. The inflate() method is then called on this instance to inflate the layout resource "dialog_layout" into a view. This view is set as the content view for an AlertDialog using the setView() method. Package library: android.view.LayoutInflater, android.app.AlertDialog