我正在开发一个数字时钟小工具。我写了代码。但它没有更新时间。我没有使用任何服务并在模拟器中运行。我的代码如下:
public class ExampleAppWidgetProvider extends AppWidgetProvider
{
DateFormat df = new SimpleDateFormat("hh:mm:ss");
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,int[] appWidgetIds)
{
final int NUM = appWidgetIds.length;
for(int i =0; i<NUM; i++)
{
int appWidgetId = appWidgetIds[i];
RemoteViews remoteview = new RemoteViews(context.getPackageName(), R.layout.widget1);
// remoteview.setOnClickPendingIntent(R.id.button, pending);
remoteview.setTextViewText(R.id.Time_text, df.format(new Date()));
appWidgetManager.updateAppWidget(appWidgetId, remoteview);
}
}
我的widget_layout.xml如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:layout_margin="4dp"
android:background="@drawable/widgetstyle"
>
<TextView
android:id="@+id/Time_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
/>
</LinearLayout>
任何人都可以帮忙吗?