Android桌面小部件实例 桌面小时钟

Android桌面小部件实例 桌面小时钟 AppWidegetProvider

/** 
* 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); 
  
                } 
        } 
  
}

 一些优秀的帖子:

沈阳公交源代码(先放一个)
http://www.eoeandroid.com/thread-229366-1-1.html

android自定义Dialog 封装
http://www.eoeandroid.com/thread-228919-1-1.html

 7个Android应用程序源代码打包下载
http://www.eoeandroid.com/thread-228832-1-1.html

 

你可能感兴趣的:(Android桌面小部件实例 桌面小时钟)