Middle
Can you give an example when the Android framework uses the Factory design pattern?
sobes.tech AI
Answer from AI
// Example of using LayoutInflater as a Factory to create a View
// Assume we are in an Activity
LayoutInflater inflater = getLayoutInflater();
// Use Factory to create View from a layout file
// LayoutInflater.inflate() is a Factory method that creates a View
View myView = inflater.inflate(R.layout.my_custom_layout, null);
// You can then work with the created View
// For example:
// TextView textView = myView.findViewById(R.id.myTextView);