Skip to main content
added 5 characters in body
Source Link
lxknvlk
  • 236
  • 1
  • 7

If i correctly understood you, then I believe, you can add a click listener to a bitmap just like to a jpg image or other format.

In my example the image_star is a png file.

ImageView img = (ImageView) findViewById(R.id.imageView1);

img.setOnClickListener(new View.OnClickListener() {
        
        @Override
        public void onClick(View v) {
            //some code
        }
    });

The xml :

    <ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignRight="@+id/imageButton1"
    android:layout_below="@+id/textView1"
    android:layout_marginTop="62dp"
    android:src="@drawable/image_star" 
    />

The result of this would be lower. The picture with a star in the middle is a clickable image, the ImageView img from my code. The upper button is an ImageButton.

enter image description here

Also there is a way to make it clickable only through the xml code, but im not sure how that is done, because i dont like that way.

If i correctly understood you, then I believe, you can add a click listener to a bitmap just like to a jpg image or other format.

In my example the image_star is a png file.

ImageView img = (ImageView) findViewById(R.id.imageView1);

img.setOnClickListener(new View.OnClickListener() {
        
        @Override
        public void onClick(View v) {
            //some code
        }
    });

The xml :

    <ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignRight="@+id/imageButton1"
    android:layout_below="@+id/textView1"
    android:layout_marginTop="62dp"
    android:src="@drawable/image_star" 
    />

The result of this would be lower. The picture with a star in the middle is a clickable image, the ImageView img from my code. The upper button is an ImageButton.

enter image description here

If i correctly understood you, then I believe, you can add a click listener to a bitmap just like to a jpg image or other format.

In my example the image_star is a png file.

ImageView img = (ImageView) findViewById(R.id.imageView1);

img.setOnClickListener(new View.OnClickListener() {
        
        @Override
        public void onClick(View v) {
            //some code
        }
    });

The xml :

    <ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignRight="@+id/imageButton1"
    android:layout_below="@+id/textView1"
    android:layout_marginTop="62dp"
    android:src="@drawable/image_star" 
    />

The result of this would be lower. The picture with a star in the middle is a clickable image, the ImageView img from my code. The upper button is an ImageButton.

enter image description here

Also there is a way to make it clickable only through the xml code, but im not sure how that is done, because i dont like that way.

added 5 characters in body
Source Link
lxknvlk
  • 236
  • 1
  • 7

If i correctly understood you, then I believe, you can add a click listener to a bitmap just like to a jpg image or other format.

In my example the image_star is a png file.

ImageView img = (ImageView) findViewById(R.id.imageView1);

img.setOnClickListener(new View.OnClickListener() {
        
        @Override
        public void onClick(View v) {
            //some code
        }
    });

The xml :

    <ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignRight="@+id/imageButton1"
    android:layout_below="@+id/textView1"
    android:layout_marginTop="62dp"
    android:src="@drawable/image_star" 
    />

The result of this would be lower. The picture with a star in the middle is a clickable image, the ImageView img from my code. The upper button is an ImageButton.

enter image description here

If i correctly understood you, then I believe, you can add a click listener to a bitmap just like to a jpg image or other format.

In my example the image_star is a png file.

ImageView img = (ImageView) findViewById(R.id.imageView1);

img.setOnClickListener(new View.OnClickListener() {
        
        @Override
        public void onClick(View v) {
            //some code
        }
    });

The xml :

    <ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignRight="@+id/imageButton1"
    android:layout_below="@+id/textView1"
    android:layout_marginTop="62dp"
    android:src="@drawable/image_star" 
    />

If i correctly understood you, then I believe, you can add a click listener to a bitmap just like to a jpg image or other format.

In my example the image_star is a png file.

ImageView img = (ImageView) findViewById(R.id.imageView1);

img.setOnClickListener(new View.OnClickListener() {
        
        @Override
        public void onClick(View v) {
            //some code
        }
    });

The xml :

    <ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignRight="@+id/imageButton1"
    android:layout_below="@+id/textView1"
    android:layout_marginTop="62dp"
    android:src="@drawable/image_star" 
    />

The result of this would be lower. The picture with a star in the middle is a clickable image, the ImageView img from my code. The upper button is an ImageButton.

enter image description here

added 5 characters in body
Source Link
lxknvlk
  • 236
  • 1
  • 7

If i correctly understood you, then I believe, you can add a click listener to a bitmap just like to a button,jpg image or toother format.

In my example the image_star is a ImageViewpng file.

ImageView img = (ImageView) findViewById(R.id.imageView1);

img.setOnClickListener(new View.OnClickListener() {
        
        @Override
        public void onClick(View v) {
            //some code
        }
    });

The xml :

    <ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignRight="@+id/imageButton1"
    android:layout_below="@+id/textView1"
    android:layout_marginTop="62dp"
    android:src="@drawable/image_star" 
    />

I havent tried it, but im sure it is possible to bind the bitmap to the ImageView and add a onclicklistener to it. In my example the image_star is a png file

If i correctly understood you, then I believe, you can add a click listener to a bitmap just like to a button, or to a ImageView.

ImageView img = (ImageView) findViewById(R.id.imageView1);

img.setOnClickListener(new View.OnClickListener() {
        
        @Override
        public void onClick(View v) {
            //some code
        }
    });

The xml :

    <ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignRight="@+id/imageButton1"
    android:layout_below="@+id/textView1"
    android:layout_marginTop="62dp"
    android:src="@drawable/image_star" 
    />

I havent tried it, but im sure it is possible to bind the bitmap to the ImageView and add a onclicklistener to it. In my example the image_star is a png file

If i correctly understood you, then I believe, you can add a click listener to a bitmap just like to a jpg image or other format.

In my example the image_star is a png file.

ImageView img = (ImageView) findViewById(R.id.imageView1);

img.setOnClickListener(new View.OnClickListener() {
        
        @Override
        public void onClick(View v) {
            //some code
        }
    });

The xml :

    <ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignRight="@+id/imageButton1"
    android:layout_below="@+id/textView1"
    android:layout_marginTop="62dp"
    android:src="@drawable/image_star" 
    />
added more information as suggested
Source Link
lxknvlk
  • 236
  • 1
  • 7
Loading
Source Link
lxknvlk
  • 236
  • 1
  • 7
Loading