Low maintainability with old Android features Medium

This code uses older Android features that make it complex and harder to maintain.

Detector ID
Common Weakness Enumeration (CWE) external icon

Noncompliant example

1public ViewHolder onCreateViewHolderNonCompliant(ViewGroup parent, int viewType) {
2    // Noncompliant: layout is created programmatically in code, without using the LayoutInflater.
3    return new ViewHolder(new TextView(parent.getContext()));

Compliant example

1public ViewHolder onCreateViewHolderCompliant(ViewGroup parent, int viewType) {
2    final Context context = parent.getContext();
3    // Compliant: LayoutInflater is used to inflate views.
4    LayoutInflater inflater = LayoutInflater.from(context);
5    View itemView = inflater.inflate(layoutResourceId, parent, false);
6    return new ViewHolder(itemView);