Android tip #023 – Optimize lists a 150%

Platform/Language: Java/XML/Android

Related with: Optimize lists a 175%

Description: 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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/* ... */

@Override
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;
}

/* ... */

Leave A Reply