1

代码如下: 它在位置 0 不应该是可点击的。我使用了 view.setClickable(false) 但它没有用。

@Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // Get the textview and imageview
        int c = ctx.getResources().getColor(R.color.expandlist);
        int selectedColor = ctx.getResources().getColor(R.color.colorexpand);
        View view = super.getView(position, convertView, parent);
        TextView textView = (TextView) view.findViewById(R.id.cust_view);

        Typeface tf = Typeface.createFromAsset(ctx.getAssets(),
                "fonts/segoeuil.ttf");
        ImageView imageView = (ImageView) view.findViewById(R.id.productImage);
        textView.setTypeface(tf);

        //Check the position so that proper values are assigned
        if (position == 0) {
            File sdCardRoot = Environment.getExternalStorageDirectory();
            File yourDir = new File(sdCardRoot, "ProductImages" + "/Main" + ID
                    + ".jpg");
            if (yourDir.getPath() != null) {
                Bitmap picture = BitmapFactory.decodeFile(yourDir.getPath());
                int width = picture.getWidth();
                int height = picture.getWidth();
                float aspectRatio = (float) width / (float) height;
                int newWidth = 149;
                int newHeight = (int) (150 / aspectRatio);
                picture = Bitmap.createScaledBitmap(picture, newWidth,
                        newHeight, true);
                imageView.setImageBitmap(picture);
                textView.setPadding(13, 200, 0, 0);


            }
            textView.setClickable(false);
            imageView.setClickable(false);
            view.setClickable(false);

        } else {
            if (position == 1) {
                if (ProductItemListFragment.videos) {
                    textView.setBackgroundColor(selectedColor);
                } else {
                    textView.setBackgroundColor(Color.TRANSPARENT);
                }
            } else if (position == 2) {
                if (ProductItemListFragment.images) {
                    textView.setBackgroundColor(selectedColor);
                } else {
                    textView.setBackgroundColor(Color.TRANSPARENT);
                }
            } else if (position == 3) {
                if (ProductItemListFragment.story) {
                    textView.setBackgroundColor(selectedColor);
                } else {
                    textView.setBackgroundColor(Color.TRANSPARENT);
                }

            } else {
                textView.setBackgroundColor(Color.TRANSPARENT);
            }
            // hide/remove image
            imageView.setVisibility(View.GONE); // or GONE, as you wish
            textView.setPadding(13, 10, 0, 15);

        }

        return view;
    }
4

0 回答 0