Posted By

Raevonium on 06/27/11


Tagged

android


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

icecreamboyy


Using getView and convertView in Android


 / Published in: Java
 

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

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

  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. }

Report this snippet  

You need to login to post a comment.