码迷,mamicode.com
首页 > 移动开发 > 详细

Android GridView 第一个Item 点击没反应

时间:2014-12-10 15:41:24      阅读:358      评论:0      收藏:0      [点我收藏+]

标签: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   

原文地址:http://www.cnblogs.com/blogzhangwei/p/4155284.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!