开发学院手机开发Android 开发 Android实现widget定时更新 阅读

Android实现widget定时更新

 2010-06-19 17:37:00 来源:WEB开发网   
核心提示:}}public class NewsWidgetProvider extends AppWidgetProvider {@Overridepublic void onDeleted(Context context, int[] appWidgetIds) {}@Overridepublic void onDisabl

}

}

public class NewsWidgetProvider extends AppWidgetProvider {

@Override

public void onDeleted(Context context, int[] appWidgetIds) {

}

@Override

public void onDisabled(Context context) {

// TODO Auto-generated method stub

super.onDisabled(context);

}

@Override

public void onEnabled(Context context) {

// TODO Auto-generated method stub

super.onEnabled(context);

}

@Override

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

NewsService.updateAppWidgetIds(appWidgetIds);

context.startService(new Intent(context,NewsService.class));

}

public static RemoteViews updateAppWidget(Context context,List list) {

RemoteViews views = new RemoteViews(context.getPackageName(),R.layout.appwidget_layout);

if (list.size() > 3) {

views.setTextViewText(R.id.textView01, list.get(0).title);

views.setTextViewText(R.id.textView02, list.get(1).title);

views.setTextViewText(R.id.textView03, list.get(2).title);

}

Intent detailIntent=new Intent(context,NewsSiteList.class);

PendingIntent pending=PendingIntent.getActivity(context, 0, detailIntent, 0);

views.setOnClickPendingIntent(R.id.textView01, pending);

views.setOnClickPendingIntent(R.id.textView02, pending);

views.setOnClickPendingIntent(R.id.textView03, pending);

return views;

}

@Override

public void onReceive(Context context, Intent intent) {

super.onReceive(context, intent);

}

}

Service:

Java代码

public class NewsService extends Service implements Runnable {

private static final String TAG="NewsService";

上一页  1 2 3 4 5 6  下一页

Tags:Android 实现 widget

编辑录入:coldstar [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接