title: How do I use a button to open a website from the browser on an Android widget?
body: <p>So I have been trying for hours to get this to work and I can't for the life of me figure it out. I have tried many different ideas I've found just googling it, but without any luck. I am trying to create an android widget that you can click on an image and it uses the default browser to open up a website. I am able to get the image and widget working correctly, but when I try to implement the code for the button to open a website, it kills the widget and says "Problem loading gadget" on the phone. I'm fairly new to making widgets/apps so any advice is appreciated.
  How can I make the widget work?</p>
  
  <p>Here is my code:</p>
  
  <p><strong>Main.xml</strong></p>
  
  <pre><code>$&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:background="@drawable/widget_frame_portrait"
  &gt;
      &lt;TextView android:id="@+id/xmas"
          android:layout_toRightOf="@+id/refresh"
          android:layout_width="wrap_content"
          android:layout_height="50dip"
          android:text="@string/hello"
          android:layout_marginTop="37dip"
          android:layout_marginBottom="25dip"
  
          android:layout_marginRight="5dip"
  
          android:orientation="vertical"
          android:textColor="#000000"/&gt;
  
      &lt;ImageButton
          android:layout_height="50dip"
          android:id="@+id/refresh"
          android:background="@drawable/feep"
          android:layout_width="225dip"
          android:layout_marginTop="25dip"
          android:layout_marginBottom="25dip"
          android:layout_marginLeft="25dip"
          android:layout_marginRight="1dip"
          android:orientation="horizontal"
  
          android:clickable="true"
          android:onClick="openWebUrl"
      /&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>My only activity called bGiving.Java:</p>
  
  <pre><code>$package chris.days.to;
  
  import android.app.Activity;
  import android.appwidget.AppWidgetManager;
  import android.appwidget.AppWidgetProvider;
  import android.content.Context;
  import android.content.Intent;
  import android.net.Uri;
  import android.view.View;
  import android.widget.Button;
  
  public class bGiving extends Activity implements View.OnClickListener  {
  
      public void onUpdate(Context context, AppWidgetManager appWidgetManager,
                           int[] appWidgetIds) {
  
      }
  
      public void openWebURL(View v) {
          String url = "http://google.com";
  
          Intent i = new Intent(Intent.ACTION_VIEW);
  
          i.setData(Uri.parse(url));
  
          startActivity(i);
      }
  
      public void onClick(View v) {
  
      }
  }
  
  and my Android Manifest is:
  
      $&lt;?xml version="1.0" encoding="utf-8"?&gt;
      &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="chris.days.to"
        android:versionCode="1"
        android:versionName="1.0"&gt;
          &lt;uses-sdk android:minSdkVersion="4" /&gt;
  
          &lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt;
  
              &lt;receiver android:name=".DaysToXmas" android:label="@string/app_name"&gt;
                  &lt;intent-filter&gt;
                      &lt;action android:name="android.appwidget.action.APPWIDGET_UPDATE" /&gt;
                  &lt;/intent-filter&gt;
                  &lt;meta-data android:name="android.appwidget.provider"
                             android:resource="@xml/hello_widget_provider" /&gt;
              &lt;/receiver&gt;
  
              &lt;activity android:name=".bGiving"
                        android:label="@string/app_name"&gt;
                  &lt;intent-filter&gt;
                      &lt;action android:name="android.intent.action.MAIN" /&gt;
                      &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
                  &lt;/intent-filter&gt;
              &lt;/activity&gt;
  
          &lt;/application&gt;
      &lt;/manifest&gt;
  </code></pre>
  
  <p>When I add in the code in the main.xml "android:onClick="openWebUrl" it kills the widget.</p>