Thursday, 15 August 2013

Open the default app when an image is pressed from a LinearLayout

Open the default app when an image is pressed from a LinearLayout

I have a LinearLayout which contains three images:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="0dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
tools:context=".MainActivity"
android:orientation="horizontal"
android:layout_gravity="center" >
<ImageView
android:id="@+id/imgFB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/fb"
android:padding="5dp" />
<ImageView
android:id="@+id/imgTW"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/tw"
android:padding="5dp" />
<ImageView
android:id="@+id/imgLIN"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/lin"
android:padding="5dp" />
</LinearLayout>
I call them inside my Activity as (dialog is being called prior):
ImageView iv1 = (ImageView) dialog.findViewById(R.id.imgFB);
ImageView iv2 = (ImageView) dialog.findViewById(R.id.imgTW);
ImageView iv3 = (ImageView) dialog.findViewById(R.id.imgLIN);
How can I use the onClick() method to open the app if it exist or open a
web browser with the URL attached to it?
//Example
public void onClick(View v) {
if (iv1 is clicked()) {
Check if FB is installed, if it is take them to my FB page
If FB is not installed, open the browser and take them to my FB
page
}
}

No comments:

Post a Comment