0

So i got a GridView displaying some flags. Each GridView cell consists of an ImageView and a TextView. Only the ImageView is shown at start. When position 1 and 240 in the GridView loads, the TextView should become visible.

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

    if (convertView == null) {
        convertView = LayoutInflater.from(mContext).inflate(R.layout.grid_images, parent, false);
        mVHolder = new ViewHolder();
        mVHolder.mImageView = (ImageView) convertView.findViewById(R.id.gridview_img);
        mVHolder.mTextView = (TextView) convertView.findViewById(R.id.textas);
        mVHolder.mTextView.setVisibility(View.INVISIBLE);
        convertView.setTag(mVHolder);
    } else {
        mVHolder = (ViewHolder) convertView.getTag();
    }
    int img = Flagcontainer.flags.get(position).getFlagThumb();


    Picasso.with(mContext).load(img).into(mVHolder.mImageView);

    if (position == 1 || position == 240) {
        mVHolder.mTextView.setVisibility(View.VISIBLE);
    }


    return convertView;
}

class ViewHolder {
    ImageView mImageView;
    TextView mTextView;
}

The problem:

When scrolled all the way to the bottom of the GridView, the TextView of cell 240 gets displayed. If one scrolls up, TextViews of other cells than 1 and 240 gets displayed.

What is wrong with my code?

See the video to visualize the problem

Video: http://www.youtube.com/watch?v=ONLLvS9ISJQ

4

1 回答 1

0

正如 el_bhm 指出的那样

if (position == 1 || position == 240) {
    mVHolder.mTextView.setVisibility(View.VISIBLE);
}

需要其他地方mVHolder.mTextView.setVisibility(View.GONE);

于 2013-06-20T20:46:03.603 回答