Skip to content

Commit 35d2d60

Browse files
committed
merging refs/heads/06_LayoutDifferentRowLayout into HEAD
2 parents 3507da7 + ea32cea commit 35d2d60

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

‎de.vogella.android.listactivity/src/de/vogella/android/listactivity/MyArrayAdapter.java‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,14 @@ public MyArrayAdapter(Activity context, String[] names) {
2020

2121
@Override
2222
public View getView(int position, View convertView, ViewGroup parent) {
23-
LayoutInflater inflater = context.getLayoutInflater();
24-
View rowView = inflater.inflate(R.layout.rowlayout, null, true);
23+
// Recycle existing view if passed as parameter
24+
// This will save memory and time on Android
25+
// This only works if the base layout for all classes are the same
26+
View rowView = convertView;
27+
if (rowView ==null){
28+
LayoutInflater inflater = context.getLayoutInflater();
29+
rowView = inflater.inflate(R.layout.rowlayout, null, true);
30+
}
2531

2632
TextView label = (TextView) rowView.findViewById(R.id.label);
2733
label.setText(names[position]);

‎de.vogella.android.listactivity/src/de/vogella/android/listactivity/MyList.java‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ public class MyList extends ListActivity {
1212
public void onCreate(Bundle icicle) {
1313
super.onCreate(icicle);
1414
// Create an array of Strings, that will be put to our ListActivity
15-
String[] names = new String[] { "Linux", "Windows7", "Eclipse", "Suse", "Ubuntu", "Solaris", "Android", "iPhone"};
15+
String[] names = new String[] { "Linux", "Windows7", "Eclipse", "Suse",
16+
"Ubuntu", "Solaris", "Android", "iPhone", "Linux", "Windows7",
17+
"Eclipse", "Suse", "Ubuntu", "Solaris", "Android", "iPhone" };
1618
this.setListAdapter(new MyArrayAdapter(this, names));
1719
}
1820

@@ -26,6 +28,5 @@ protected void onListItemClick(ListView l, View v, int position, long id) {
2628
.show();
2729

2830
}
29-
30-
31+
3132
}

0 commit comments

Comments
 (0)