MKK
MKK

Reputation: 2753

How can I enable jumping to linked page if user clicks TextView?

XML Layout

<LinearLayout style="@style/behindMenuScrollContent"
    android:paddingTop="25dp" >

    <TextView
        style="@style/behindMenuItemTitle"
        android:text="People" />

    <LinearLayout
        android:id="@+id/iconViewLink4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <jp.fureco.IconView 
            android:id="@+id/iconViewItem4"
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp"
            android:textSize="20dp"/>

        <TextView
            android:layout_marginLeft="10dp"
            style="@style/behindMenuItemLabel"
            android:text="Visitor" />

    </LinearLayout>

</LinearLayout>

Then I have myWebView just like this

WebView  myWebView = (WebView)findViewById(R.id.webView1);

When a user clicks on iconViewLink4, I want it jump to the url "http://example.com/messsage"

How can I code that?

Upvotes: 0

Views: 36

Answers (2)

Karakuri
Karakuri

Reputation: 38605

Make it clickable and give it an OnClickListener (you can do this on any View)

<LinearLayout
    android:id="@+id/iconViewLink4"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:clickable="true">

findViewById(R.id.iconViewLink4).setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        // do something here
    }
});

Upvotes: 1

Ritesh Gune
Ritesh Gune

Reputation: 16739

Yes you can. Just use android:onClick="methodName" in <LinearLayout> or add it programatically by using setOnClickListener like

LinearLayout linLay = (LinearLayout)findViewById(R.id.iconViewLink4);

linLay.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        // the method or code that will take control to your URL
    }
}

Upvotes: 1

Related Questions