频道栏目
IT货架 > > 正文
Android GridView 第一个Item 点击没反应
网友分享于:Jan 1, 1970 8:00:00 AM    来源: IT货架   

标签:android   style   blog   io   ar   color   os   sp   on   

  @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 点击没反应

标签:android   style   blog   io   ar   color   os   sp   on   

相关板块推荐 iPhone WindowsPhone

广告服务联系QQ:1134687142 | 网站地图

版权所有: IT货架- 内容来自互联网,仅供用于技术学习,请遵循相关法律法规. 京ICP备11030978号-1