WEB开发网
开发学院手机开发Android 开发 Android AppWidget 开发实例 阅读

Android AppWidget 开发实例

 2010-05-27 17:04:00 来源:WEB开发网   
核心提示:3. mContext = context;4. RemoteViews views = newRemoteViews(context.getPackageName(),R.layout.main);5. Calendar6. cal=Calendar.getInstance();7. System.out.print

3. mContext = context;

4. RemoteViews views = newRemoteViews(context.getPackageName(),R.layout.main);

5. Calendar

6. cal=Calendar.getInstance();

7. System.out.println(cal.getTime().toLocaleString());

8. views.setTextViewText(R.id.txttim,cal.getTime().toLocaleString());

9. appWidgetManager.updateAppWidget(appWidgetIds,views);

10. myThread.start();

11. /**

12. * 本类作为一个bracastReveiver能自己再,注册个监听器

13. (可以取消注释,看报什么错误)

14. */

15. //

16. context.registerReceiver(mBroadcast,new IntentFilter(Intent.ACTION_TIME_TICK));

17. }

18. @Override

19. public void onReceive(Contextcontext, Intent intent) {

20. Log.d(tag,”onReceive”);

21. String action =intent.getAction();

22. Log.d(tag, “theaction is “+action);

23. if (FRESH.equals(action)){

24. showTime(context);

25. }elseif(Intent.ACTION_TIME_TICK.equals(action)){

26. showTime(context);

27. }

28. super.onReceive(context,intent);

29. }

30. private void showTime(Contextcontext) {

31. RemoteViews views = newRemoteViews(context.getPackageName(),R.layout.main);

32. Calendar

33. cal=Calendar.getInstance();

34. views.setTextViewText(R.id.txttim,cal.getTime().toLocaleString());

35. ComponentName thisWidget =new ComponentName(context,TestAppWidget.class);

36. AppWidgetManager.getInstance(context).updateAppWidget(thisWidget,views);

37. }

38. public void onDisabled(Contextcontext) {

39. Log.d(tag,”onDisabled”);

40. super.onDisabled(context);

41. run = false ;

42. }

43. }

复制代码

以上代码就是用来 改变显示时间和处理刷新FRESHIntent的主程序。

上一页  1 2 3 4 5  下一页

Tags:Android AppWidget 开发实例

编辑录入:coldstar [复制链接] [打 印]
赞助商链接