Optimize lists a 150%

Optimize lists a 150%

We can optimize the Adapters attached to a ListView inflating our custom layouts when it is necessary. This process is easy to implement with only one condition (Android will managed the rest of the work).

// MyAdapter.java

public View getView(int position, View convertView, ViewGroup parent) {
    View row = convertView;

    if (row == null) {
        LayoutInflater inflater = (LayoutInflater) this.mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        row = inflater.inflate(R.layout.your_row_layout, null);     

    // Populate row
    // ...

    return row;

NOTE: related post: Optimize lists a 175%