我想创建一个小部件来显示所有在线用户真的很容易在Android应用程序中执行此操作 但我想创建一个小部件
有没有办法做到这一点?
public class WatchWidget extends AppWidgetProvider {
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
// TODO Auto-generated method stub
super.onUpdate(context, appWidgetManager, appWidgetIds);
RemoteViews remoteViews;
ComponentName watchWidget;
java.text.DateFormat format = SimpleDateFormat.getTimeInstance(
SimpleDateFormat.MEDIUM, Locale.getDefault());
remoteViews = new RemoteViews(context.getPackageName(), R.layout.activity_main);
watchWidget = new ComponentName(context, WatchWidget.class);
remoteViews.setTextViewText(R.id.textView,
"Time = " + format.format(new Date()));
appWidgetManager.updateAppWidget(watchWidget, remoteViews);
}
}