How to Set onClicklistener Method of ImageView in Android?

后端 未结 3 572
盖世英雄少女心
盖世英雄少女心 2020-12-30 06:58

I am Adding an array of ImageViews and set an image to each ImageView dynamically and I\'m done with it. But the problem is how to set/define onCl

相关标签:
3条回答
  • 2020-12-30 07:14
    for (floop = 0; floop < sandleicon.length; floop++) {
        mImages[floop] = new ImageView(this);
        mImages[floop].setImageResource(images[floop]);
        mImages[floop].setId(floop);
        ll.addView(mImages[floop]);
        mImages[floop].setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                //v.getId() will give you the image id
            }
        });
    }
    
    0 讨论(0)
  • 2020-12-30 07:15

    This worked for me in fragment

        // update the Youtube thumbnail images
            this.youtube_thumbnail = (ImageView) listView.findViewById(R.id.youtube_thumbnail);
    
            this.youtube_thumbnail.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
    
                    System.out.println("Adding youtube thumbnail");
    
                }
            });
    
    0 讨论(0)
  • 2020-12-30 07:20
    mImages[floop].setOnClickListener(clickListener);
    
    private OnClickListener clickListener = new OnClickListener() {
    
            public void onClick(View v) {
    
            }
    };
    

    This is how you set onclicklistener to any view.

    0 讨论(0)
提交回复
热议问题