开发者

Click event for android widget to navigate a website

I am developing开发者_StackOverflow社区 an application on android 2.2. My application shows job count on widget. When i click on this widget, user has to redirected to a website.

Here how can we implement click event for widget, which has background image with TextView.

Please help me regarding this.


Check out the following tutorial

http://developer.android.com/guide/topics/appwidgets/index.html

The onUpdate event of the AppWidgetProvider is what you are looking for. The above page has a sections on it. Basically you could do something like the following in your AppWidgetProvider class.

public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {

  /* loop through each widgets created by this provider and do the following */

  Intent intent = new Intent(context, ExampleActivity.class);
  PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);

  // Get the layout for the App Widget and attach an on-click listener to the button
  RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget_provider_layout);
  views.setOnClickPendingIntent(R.id.button, pendingIntent);

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜