[android]代码库
/**
* Android桌面小部件实例 桌面小时钟
*/
public class EX04_28 extends AppWidgetProvider {
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
// TODO Auto-generated method stub
/* 新起UpdateService的Intent */
Intent intent = new Intent(context, UpdateService.class);
context.startService(intent);
super.onUpdate(context, appWidgetManager, appWidgetIds);
}
public static class UpdateService extends Service {
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
/* 取得Widget的View */
RemoteViews updateViews = new RemoteViews(this.getPackageName(),
R.layout.main);
/* 格式化时间hh:mm占表时跟分 */
SimpleDateFormat sdf = new SimpleDateFormat("hh:mm");
/* 将时间放置TextView */
updateViews.setTextViewText(R.id.TextView01,
"" + sdf.format(new Date()));
/* 更新widget */
ComponentName thisWidget = new ComponentName(this, EX04_28.class);
AppWidgetManager manager = AppWidgetManager.getInstance(this);
manager.updateAppWidget(thisWidget, updateViews);
}
}
}
初级程序员
by: 小蘑菇 发表于:2013-05-05 23:14:22 顶(0) | 踩(0) 回复
收藏,备用
回复评论