Wednesday, 15 June 2011

java - How to open a browser through a Relative Layout -



java - How to open a browser through a Relative Layout -

i have tried next 2 different links no success.

http://stackoverflow.com/questions/3536165/how-can-imageview-link-to-web-page

and

http://stackoverflow.com/questions/3505788/how-to-open-default-browser/3505804#3505804

i apologize if simple prepare i'm nooby , getting frustrated because according examples should work.

here xml layout

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/grey" android:orientation="vertical" > <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginleft="5sp" android:layout_marginright="5sp" android:layout_margintop="5sp" android:background="@color/grey" android:gravity="center_horizontal" android:orientation="horizontal" android:padding="5sp" > <imageview android:id="@+id/logo_about" android:layout_width="85dp" android:layout_height="105dp" android:layout_gravity="center_vertical" android:layout_weight="0.11" android:src="@drawable/web_icon" /> </linearlayout> <textview android:id="@+id/tv_content_about" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginleft="5sp" android:layout_marginright="5sp" android:layout_margintop="5sp" android:background="@color/grey" android:gravity="center_horizontal" android:padding="5sp" android:text="@string/info_about_us" android:textcolor="@color/black" android:textsize="15sp" /> <!-- contact --> <relativelayout android:id="@+id/contact" android:clickable="true" android:focusable="false" android:layout_width="match_parent" android:layout_height="50sp" android:background="@drawable/btn_bg" > <imageview android:id="@+id/img_icon" android:clickable="true" android:layout_width="40sp" android:layout_height="40sp" android:layout_centervertical="true" android:layout_marginleft="5sp" android:scaletype="fitxy" android:src="@drawable/icon_email" /> <textview android:id="@+id/tv_name" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_aligntop="@+id/img_icon" android:layout_marginleft="5sp" android:layout_marginright="5sp" android:layout_toleftof="@+id/img_indicator" android:layout_torightof="@+id/img_icon" android:singleline="true" android:text="@string/title_contact_us" android:textcolor="@color/black" android:textsize="15sp" android:textstyle="bold" /> <textview android:id="@+id/tv_content" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignleft="@+id/tv_name" android:layout_alignright="@+id/tv_name" android:layout_below="@+id/tv_name" android:singleline="true" android:text="@string/info_contact_us" android:textcolor="@color/black" android:textsize="13sp" /> <imageview android:id="@+id/img_indicator" android:clickable="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentright="true" android:layout_centervertical="true" android:layout_marginright="5sp" android:src="@drawable/ic_action_next_item" /> <view android:id="@+id/devider" android:layout_width="match_parent" android:layout_height="1dp" android:layout_alignparentbottom="true" android:background="@color/grey" /> </relativelayout> <!-- facebook --> <relativelayout android:layout_width="match_parent" android:layout_height="50sp" android:clickable="true" android:background="@drawable/btn_bg" > <imageview android:id="@+id/facebook_icon" android:layout_width="40sp" android:layout_height="40sp" android:layout_centervertical="true" android:layout_marginleft="5sp" android:scaletype="fitxy" android:src="@drawable/icon_facebook" /> <textview android:id="@+id/tv_name1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_aligntop="@+id/facebook_icon" android:layout_marginleft="5sp" android:layout_marginright="5sp" android:layout_toleftof="@+id/facebook_icon" android:layout_torightof="@+id/facebook_icon" android:singleline="true" android:text="@string/title_facebook" android:textcolor="@color/black" android:textsize="15sp" android:textstyle="bold" /> <textview android:id="@+id/tv_content1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignleft="@+id/tv_name1" android:layout_alignright="@+id/tv_name1" android:layout_below="@+id/tv_name1" android:singleline="true" android:text="@string/info_facebook" android:textcolor="@color/black" android:textsize="13sp" /> <imageview android:id="@+id/img_indicator1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentright="true" android:layout_centervertical="true" android:layout_marginright="5sp" android:src="@drawable/ic_action_next_item" /> <view android:layout_width="match_parent" android:layout_height="1dp" android:layout_alignparentbottom="true" android:background="@color/grey" /> </relativelayout> <!-- google plus --> <relativelayout android:layout_width="match_parent" android:layout_height="50sp" android:clickable="true" android:background="@drawable/btn_bg" > <imageview android:id="@+id/google_icon" android:layout_width="40sp" android:layout_height="40sp" android:layout_centervertical="true" android:layout_marginleft="5sp" android:scaletype="fitxy" android:src="@drawable/icon_googleplus" /> <textview android:id="@+id/tv_name2" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_aligntop="@+id/google_icon" android:layout_marginleft="5sp" android:layout_marginright="5sp" android:layout_toleftof="@+id/google_icon" android:layout_torightof="@+id/google_icon" android:singleline="true" android:text="@string/title_google_plus" android:textcolor="@color/black" android:textsize="15sp" android:textstyle="bold" /> <textview android:id="@+id/tv_content2" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignleft="@+id/tv_name2" android:layout_alignright="@+id/tv_name2" android:layout_below="@+id/tv_name2" android:singleline="true" android:text="@string/info_google_plus" android:textcolor="@color/black" android:textsize="13sp" /> <imageview android:id="@+id/img_indicator2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentright="true" android:layout_centervertical="true" android:layout_marginright="5sp" android:src="@drawable/ic_action_next_item" /> <view android:layout_width="match_parent" android:layout_height="1dp" android:layout_alignparentbottom="true" android:background="@color/grey" /> </relativelayout> <!-- website --> <relativelayout android:layout_width="match_parent" android:layout_height="50sp" android:background="@drawable/btn_bg" > <imageview android:id="@+id/website_icon" android:layout_width="40sp" android:layout_height="40sp" android:layout_centervertical="true" android:layout_marginleft="5sp" android:scaletype="fitxy" android:src="@drawable/icon_website" /> <textview android:id="@+id/tv_name3" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_aligntop="@+id/website_icon" android:layout_marginleft="5sp" android:layout_marginright="5sp" android:layout_toleftof="@+id/img_indicator3" android:layout_torightof="@+id/website_icon" android:singleline="true" android:text="@string/title_website" android:textcolor="@color/black" android:textsize="15sp" android:textstyle="bold" /> <textview android:id="@+id/tv_content3" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignleft="@+id/tv_name3" android:layout_alignright="@+id/tv_name3" android:layout_below="@+id/tv_name3" android:singleline="true" android:text="@string/info_website" android:textcolor="@color/black" android:textsize="13sp" /> <imageview android:id="@+id/img_indicator3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentright="true" android:layout_centervertical="true" android:layout_marginright="5sp" android:src="@drawable/ic_action_next_item" /> <view android:layout_width="match_parent" android:layout_height="1dp" android:layout_alignparentbottom="true" android:background="@color/grey" /> </relativelayout> <!-- rate --> <relativelayout android:layout_width="match_parent" android:layout_height="50sp" android:background="@drawable/btn_bg" > <imageview android:id="@+id/rate_icon" android:layout_width="40sp" android:layout_height="40sp" android:layout_centervertical="true" android:layout_marginleft="5sp" android:scaletype="fitxy" android:src="@drawable/icon_rate_me" /> <textview android:id="@+id/tv_name4" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_aligntop="@+id/rate_icon" android:layout_marginleft="5sp" android:layout_marginright="5sp" android:layout_toleftof="@+id/img_indicator4" android:layout_torightof="@+id/rate_icon" android:singleline="true" android:text="@string/title_rate_us" android:textcolor="@color/black" android:textsize="15sp" android:textstyle="bold" /> <textview android:id="@+id/tv_content4" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignleft="@+id/tv_name4" android:layout_alignright="@+id/tv_name4" android:layout_below="@+id/tv_name4" android:singleline="true" android:text="@string/info_rate_us" android:textcolor="@color/black" android:textsize="13sp" /> <imageview android:id="@+id/img_indicator4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentright="true" android:layout_centervertical="true" android:layout_marginright="5sp" android:src="@drawable/ic_action_next_item" /> <view android:layout_width="match_parent" android:layout_height="1dp" android:layout_alignparentbottom="true" android:background="@color/grey" /> </relativelayout> <!-- more apps --> <relativelayout android:layout_width="match_parent" android:layout_height="50sp" android:background="@drawable/btn_bg" > <imageview android:id="@+id/apps_icon" android:layout_width="40sp" android:layout_height="40sp" android:layout_centervertical="true" android:layout_marginleft="5sp" android:scaletype="fitxy" android:src="@drawable/icon_more_app" /> <textview android:id="@+id/tv_name5" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_aligntop="@+id/apps_icon" android:layout_marginleft="5sp" android:layout_marginright="5sp" android:layout_toleftof="@+id/img_indicator5" android:layout_torightof="@+id/apps_icon" android:singleline="true" android:text="@string/title_more_app" android:textcolor="@color/black" android:textsize="15sp" android:textstyle="bold" /> <textview android:id="@+id/tv_content5" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignleft="@+id/tv_name5" android:layout_alignright="@+id/tv_name5" android:layout_below="@+id/tv_name5" android:singleline="true" android:text="@string/info_more_app" android:textcolor="@color/black" android:textsize="13sp" /> <imageview android:id="@+id/img_indicator5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentright="true" android:layout_centervertical="true" android:layout_marginright="5sp" android:src="@drawable/ic_action_next_item" /> <view android:layout_width="match_parent" android:layout_height="1dp" android:layout_alignparentbottom="true" android:background="@color/grey" /> </relativelayout> </linearlayout>

now fragment.java

package com.wny.wecare.fragment; import android.app.fragment; import android.content.intent; import android.net.uri; import android.os.bundle; import android.view.layoutinflater; import android.view.view; import android.view.view.onclicklistener; import android.view.viewgroup; import android.widget.imageview; import com.wny.wecare.r; public class aboutusfragment extends fragment implements onclicklistener { public static final string tag = aboutusfragment.class.getsimplename(); private view mrootview; @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { mrootview = inflater.inflate(r.layout.fragment_about_us, container, false); homecoming mrootview; } @override public void onclick(view v) { // todo auto-generated method stub imageview img = (imageview) getview().findviewbyid(r.id.img_indicator); img.setonclicklistener(new view.onclicklistener() { public void onclick(view view) { startactivity(new intent(intent.action_view, uri.parse("http://infinitycodeservices.com"))); } }); } }

do rather bro

@override public void onclick(view v) { // todo auto-generated method stub imageview img = (imageview) getview().findviewbyid(r.id.img_indicator); if(v == img) context.startactivity(new intent(intent.action_view,uri.parse("http://infinitycodeservices.com"))); //context stands 4 ur activity }

edit 1: alter intent intent reason before variable error..

so retry & seee

let me know if works.. im feeling left something.

java android eclipse android-fragments

No comments:

Post a Comment