简体   繁体   中英

in listview android items repeating

public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) this.mContext.getSystemService("layout_inflater");

    if (convertView != null) {
        return convertView;
    }

    list = new View(this.mContext);
    list = inflater.inflate(R.layout.rowsset, null);
    imageView = (ImageView) list.findViewById(R.id.pic1);
    textView1 = (TextView) list.findViewById(R.id.det2);
    textView2 = (TextView) list.findViewById(R.id.kite1);
    textView1.setText(this.web[position]);
    textView2.setText(this.web1[position]);
    imageView.setImageResource(this.Imageid[position]);

    return list;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
final View result;
if (convertView == null) {

    viewHolder = new ViewHolder();
    LayoutInflater inflater = LayoutInflater.from(mContext);
    convertView = inflater.inflate(R.layout.rowsset, parent, false);
    imageView = (ImageView) convertView.findViewById(R.id.pic1);
    textView1 = (TextView) convertView.findViewById(R.id.det2);
    textView2 = (TextView) convertView.findViewById(R.id.kite1); 

    result=convertView;
    convertView.setTag(viewHolder);
} else {
    viewHolder = (ViewHolder) convertView.getTag();
    result=convertView;
}

viewHolder.textView1.setText(this.web[position]);
viewHolder.textView2.setText(this.web1[position]);
viewHolder.imageView.setImageResource(this.Imageid[position]);

// Return the completed view to render on screen
return convertView;
}
// Please this line mention in your adapter's constructor
inflater = LayoutInflater.from(context);

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    convertView = inflater.inflate(R.layout.rowsset, null);
    imageView = (ImageView) list.findViewById(R.id.pic1);
    textView1 = (TextView) list.findViewById(R.id.det2);
    textView2 = (TextView) list.findViewById(R.id.kite1);
    textView1.setText(web[position]);
    textView2.setText(web1[position]);
    imageView.setImageResource(Imageid[position]);

    return convertView;
}

Hope this will work...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM