片段与动态CircleImageview和OnClickListener

时间:2015-04-21 10:50:46

标签: java android android-fragments

我需要在Fragment上创建Dynamic CircleImageview。要创建circleimageview,我使用的是https://github.com/hdodenhof/CircleImageView

for (int i = 0; i < Home.arr_category_item_list.size(); i++) {
        final CircleImageView circleImageView = new CircleImageView(getActivity());
        circleImageView.setId(i);
        circleImageView.setBorderColor(getResources().getColor(R.color.gray_border));
        circleImageView.setBorderWidth(5);
        circleImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
}

如何为此CircleImageView制作OnClickListener

1 个答案:

答案 0 :(得分:0)

获取圆形图像视图的数组并单击侦听器

final ArrayList<CircleImageView> circleImageViewlist = new ArrayList< CircleImageView>();
                for (int i = 0; i < Home.arr_category_item_list.size(); i++) {
                    final CircleImageView circleImageView = new CircleImageView(getActivity());
                    circleImageView.setId(i);
                    circleImageView.setBorderColor(getResources().getColor(R.color.gray_border));
                    circleImageView.setBorderWidth(5);
                    circleImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                    circleImageViewlist.add(circleImageView);
                    circleImageViewlist.get(i).setOnClickListener(this);

                    }

                        @Override
                        public void onClick(View v) {
                            for(int i = 0; i < Home.arr_category_item_list.size(); i++){
                                if(circleImageViewlist.get(i).getId()== v.getId()){
                                    //do your stuff
                                }
                            }
                        }