0

In my overflow menu I have a popup window that displays About information. It works fine, but I wanted to add a clickable link to my website and I can't get it to work. The code so far is:

         case R.id.about:
              LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              View popupView = inflater.inflate(R.layout.about_dialog, null);
              PopupWindow pw = new PopupWindow(popupView, width, width, true);
              TextView link = (TextView)findViewById(R.id.urlLink);
              link.setMovementMethod(LinkMovementMethod.getInstance());
              pw.showAtLocation(new LinearLayout(this), Gravity.CENTER, 0, 0);
          return true;

I've defined a string in resources as:

<resources>
    <string name="webLink"><a href="www.google.com">www.google.com</a></string>
</resources>

And the chunk in the XML itself is:

 <TextView
        android:id="@+id/urlLink"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:textSize="24sp"
        android:textStyle="bold"
        android:gravity="center"
        android:text="@string/webLink" />

It seems to crash when it gets to the setMovementMethod line.

Can anybody see what I've missed? Thanks & best wishes Tony Reynolds

  • 1
    `TextView link = (TextView)findViewById(R.id.urlLink);` – You need to call `findViewById()` on the `View` you just inflated, not on the `Activity`; e.g., `TextView link = (TextView) popupView.findViewById(R.id.urlLink);`. https://stackoverflow.com/q/35659255 – Mike M. Aug 05 '21 at 15:03
  • 1
    That works! I'm still very new at Android programming & grateful for the help.. – user3194684 Aug 05 '21 at 15:24

1 Answers1

0

I'm putting up this answer to show that Mike M's comment fixed it.