首页 > 代码库 > Android GridView 第一个Item 点击没反应

Android GridView 第一个Item 点击没反应

  @Override    public View getView(final int position, View convertView, ViewGroup parent) {        final ViewHolder viewHolder;        final String path = list.get(position);        if (convertView == null) {            convertView = mInflater.inflate(R.layout.grid_child_item, null);            viewHolder = new ViewHolder();            viewHolder.mLinearLayout = (FrameLayout) convertView.findViewById(R.id.childLinearLayout);            viewHolder.mImageView = (MyImageView) convertView.findViewById(R.id.child_image);            viewHolder.mCheckBox = (CheckBox) convertView.findViewById(R.id.child_checkbox);            convertView.setTag(viewHolder);        } else {            viewHolder = (ViewHolder) convertView.getTag();            viewHolder.mImageView.setImageResource(R.drawable.friends_sends_pictures_no);        }        viewHolder.mLinearLayout.getLayoutParams().height = mGridView.getWidth() / 3;        viewHolder.mImageView.setTag(path);        viewHolder.mImageView.setOnMeasureListener(new MyImageView.OnMeasureListener() {            @Override            public void onMeasureSize(int width, int height) {                mPoint.set(width, height);            }        });        viewHolder.mCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {            @Override            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {                addAnimation(viewHolder.mCheckBox, viewHolder.mImageView);            }        });        viewHolder.mImageView.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                if (viewHolder.mCheckBox.isChecked() || baseApplication.IsMaxCount() == false) {                    if (viewHolder.mCheckBox.isChecked()) {                        viewHolder.mCheckBox.setChecked(false);                    } else {                        viewHolder.mCheckBox.setChecked(true);                    }                    viewHolder.mCheckBox.setFocusable(false);                }            }        });        if (baseApplication.fetchListPath().contains(path)) {            viewHolder.mCheckBox.setChecked(true);        } else {            viewHolder.mCheckBox.setChecked(false);        }        Bitmap bitmap = null;        if (!isScrollStatue()) {            bitmap = NativeImageLoader.getInstance().loadNativeImage(path, mPoint,                    new NativeImageLoader.NativeImageCallBack() {                        @Override                        public void onImageLoader(Bitmap bitmap, String path) {                            ImageView mImageView = (ImageView) mGridView.findViewWithTag(path);                            if (bitmap != null && mImageView != null) {                                mImageView.setImageBitmap(bitmap);                            }                        }                    });        }        if (bitmap != null) {            viewHolder.mImageView.setImageBitmap(bitmap);        } else {            viewHolder.mImageView.setImageResource(R.drawable.friends_sends_pictures_no);        }        return convertView;    }
要这样设置高度 viewHolder.mLinearLayout.getLayoutParams().height = mGridView.getWidth() / 3;
否则第一个item点击没反应

Android GridView 第一个Item 点击没反应