<?xml version="1.0" encoding="utf-8"?> <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" android:minWidth="50dip" android:minHeight="50dip" android:updatePeriodMillis="10000" android:initialLayout="@layout/main" />
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/wordcup" > <TextView android:id="@+id/wordcup" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" android:textSize="12px" android:textColor="#ff0000" /> </LinearLayout>
package com.android.tutor;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Timer;
import java.util.TimerTask;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.widget.RemoteViews;
public class WidetDemo extends AppWidgetProvider {
/** Called when the activity is first created. */
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
Timer timer = new Timer();
timer.scheduleAtFixedRate(new MyTime(context,appWidgetManager), 1, 60000);
super.onUpdate(context, appWidgetManager, appWidgetIds);
}
private class MyTime extends TimerTask{
RemoteViews remoteViews;
AppWidgetManager appWidgetManager;
ComponentName thisWidget;
public MyTime(Context context,AppWidgetManager appWidgetManager){
this.appWidgetManager = appWidgetManager;
remoteViews = new RemoteViews(context.getPackageName(),R.layout.main);
thisWidget = new ComponentName(context,WidetDemo.class);
}
public void run() {
Date date = new Date();
Calendar calendar = new GregorianCalendar(2010,06,11);
long days = (((calendar.getTimeInMillis()-date.getTime())/1000))/86400;
remoteViews.setTextViewText(R.id.wordcup, "距离南非世界杯还有" + days+"天");
appWidgetManager.updateAppWidget(thisWidget, remoteViews);
}
}
}
函数调用周期 [启动 - 无confiure Activity] onReceive onEnabled —— 第一个widget被显示 onReceive onUpdate —— 刷新界面 [启动 - 带confiuration Activity] onReceive onUpdate [拖动] <无状态变化> [周期更新] onReceive onUpdate [删除] onReceive onDeleted —— widget被删除 onReceive onDisabled —— 最后一个widget被移除 [启动时位置不够] onReceive onEnabled onReceive onUpdate onReceive onDeleted onReceive onDisabled
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.tutor"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<receiver android:name=".WidetDemo"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/widget_provider"
/>
</receiver>
</application>
<uses-sdk android:minSdkVersion="7" />
</manifest>
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="hello">Hello World, WidetDemo!</string> <string name="app_name">DaysToWorldCup</string> </resources>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有