Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can ImageView link to web page?

Tags:

android

is it possible to make an imageview link to a web page such that when user taps on the image, it takes them to a web page?

like image 977
Dean-O Avatar asked Aug 21 '10 03:08

Dean-O


People also ask

Is ImageView clickable?

To make a View clickable so that users can tap (or click) it, add the android:onClick attribute in the XML layout and specify the click handler. For example, you can make an ImageView act like a simple Button by adding android:onClick to the ImageView . In this task you make the images in your layout clickable.

Can ImageView display video?

You can add ImageView and VideoView in RelativeLayout and set ImageView to invisible and VideoView to visible and vice-versa and you can play video on onClick.


1 Answers

Just add a click listener to the image to open an URL:

ImageView img = (ImageView)findViewById(R.id.foo_bar); img.setOnClickListener(new View.OnClickListener(){     public void onClick(View v){         Intent intent = new Intent();         intent.setAction(Intent.ACTION_VIEW);         intent.addCategory(Intent.CATEGORY_BROWSABLE);         intent.setData(Uri.parse("http://casidiablo.net"));         startActivity(intent);     } }); 
like image 197
Cristian Avatar answered Sep 20 '22 06:09

Cristian