2013年2月2日 星期六
button in widget
package com.example.widgettest;
import java.text.SimpleDateFormat;
import java.util.Date;
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.widget.RemoteViews;
public class MyWidget extends AppWidgetProvider {
@Override
public void onUpdate(Context context,AppWidgetManager appWidgetManager, int[] appWidgetIds) {
//RemoteViews updateViews = new RemoteViews( context.getPackageName(), R.layout.main);
//updateViews.setTextViewText(R.id.now, new SimpleDateFormat( "yyyy/MM/dd HH:mm:ss" ).format( new Date() ) );
//appWidgetManager.updateAppWidget(appWidgetIds, updateViews);
Intent startServiceInten=new Intent("com.example.widgettest.sv");
PendingIntent Pintent= PendingIntent.getService(context, 0, startServiceInten, 0);
RemoteViews views= new RemoteViews(context.getPackageName(), R.layout.main);
views.setOnClickPendingIntent(R.id.imageButton1, Pintent);
appWidgetManager.updateAppWidget(appWidgetIds, views);
}
}
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言