我使用网格视图,滚动后2-3次网格视图图像在android中变得不可见

时间:2017-05-30 10:04:42

标签: android

我使用网格视图,滚动后2-3次网格视图图像在android中变得不可见 代码点击here

1 个答案:

答案 0 :(得分:0)

试试这段代码: -

public class MyProfileArrayAdapter extends BaseAdapter {

Context context;

ArrayList<MyProfileBean> myProfileBeen1;
View gridViewAndroid;

public MyProfileArrayAdapter(Context context, ArrayList<MyProfileBean> myProfileBeen1) {
    this.context = context;
    this.myProfileBeen1 = myProfileBeen1;

}

@Override
public int getCount() {
    return myProfileBeen1.size;
}

@Override
public Object getItem(int position) {
    return null;
}

@Override
public long getItemId(int position) {
    return 0;
}

@Override
public int getViewTypeCount() {
    int Count = myProfileBeen1.size;
    return Count;
}

@Override
public int getItemViewType(int position) {
    return position;
}


   /*private view holder class*/


public View getView(int position, View convertView, ViewGroup parent) {
    final ViewHolder holder;

    if (convertView == null) {

        LayoutInflater inflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);

        convertView = inflater.inflate(R.layout.myprofile_adapter, parent, false);


        holder.view2 = (TextView) convertView.findViewById(R.id.UrlimageText);

        holder.view4 = (ImageView) convertView.findViewById(R.id.Urlimage);
    }
    else {
        holder = (ViewHolder) convertView.getTag();
    }
    holder.view2.setText(myProfileBeen1.get(position).getName());


    if (myProfileBeen1.get(position).getUrl().equals("")) {
        Picasso.with(this.context)
                .load(R.drawable.defaultbignewone)
                .centerCrop()
                .noFade()
                .resize(150, 150)

                .error(R.drawable.defaultbignewone)
                .into(holder.view4);

    } else {
        Picasso.with(context)
                .load(myProfileBeen1.get(position).getUrl())
                .placeholder(R.drawable.defaultbignewone)
                .centerCrop()
                .noFade()
                .resize(150, 150)
                .into(holder.view4);
    }


    return convertView;

}

private static class ViewHolder {

    TextView view2;
    ImageView view4;

}

}