Using getView and convertView in Android


/ Published in: Java
Save to your folder(s)

The right way (According to Google I/O-10) to use getView with the convertView-param within a custom adapter class.


Copy this code and paste it in your HTML
  1. public View getView(int position, View convertView, ViewGroup parent) {
  2. if (convertView == null) {
  3. convertView = mInflater.inflate(R.layout.item, parent, false);
  4. }
  5. ((TextView) convertView.findViewById(R.id.text)).setText(DATA[position]);
  6. ((ImageView) convertView.findViewById(R.id.icon)).setImageBitmap(
  7. (position & 1) == 1 ? mIcon1 : mIcon2);
  8. return convertView;
  9. }

URL: http://www.google.com/intl/sv-SE/events/io/2010/sessions/world-of-listview-android.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.