2015-04-21 82 views
-1

我需要在Fragment上創建動態CircleImageview。爲了創建circleimageview我使用https://github.com/hdodenhof/CircleImageView帶動態CircleImageview和OnClickListener的片段

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); 
} 

如何使OnClickListener這個CircleImageView您的圓形imageviews的

+1

創建setOnClikcListener到CircleImageView。 –

回答

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 
           } 
          } 
         }