• 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点击没反应
  • 相关阅读:
    线程池小结(一)
    [转]ViewPager学习笔记(一)——懒加载
    [转]Private Libraries、Referenced Libraries、Dependency Libraries的区别
    关于context你必须知道的一切
    【转】在mac上配置安卓SDK
    【转】HTTP中的长连接和短连接分析
    中间件解析FDMEMTABLE.delta生成SQL的方法
    delphi 中配置文件的使用(*.ini)和TIniFile 用法
    Delphi 字符串加密与解密函数
    Delphi编写的等长加密与解密
  • 原文地址:https://www.cnblogs.com/blogzhangwei/p/4155284.html
Copyright © 2020-2023  润新知