Макет
Код: Выделить всё
Код: Выделить всё
class PongClockWidget : AppWidgetProvider() {
private var pongThread: PongThread? = null
override fun onUpdate(
context: Context,
appWidgetManager: AppWidgetManager,
appWidgetIds: IntArray
) {
// There may be multiple widgets active, so update all of them
for (appWidgetId in appWidgetIds) {
updateAppWidget(context, appWidgetManager, appWidgetId,pongThread)
}
}
override fun onEnabled(context: Context) {
// Enter relevant functionality for when the first widget is created
}
override fun onDisabled(context: Context) {
// Enter relevant functionality for when the last widget is disabled
}
}
@SuppressLint("RemoteViewLayout")
internal fun updateAppWidget(
context: Context,
appWidgetManager: AppWidgetManager,
appWidgetId: Int,
pongThreadWidget: PongThread?
) {
// Construct the RemoteViews object
var pongThread = pongThreadWidget
val views = RemoteViews(context.packageName, R.layout.pong_clock_widget)
val inflated = views.apply(context, FrameLayout(context));
pongThread = ((inflated as FrameLayout).getChildAt(0) as
rpt.tool.pongclock.utils.view.PongTimeView).thread
// Instruct the widget manager to update the widget
appWidgetManager.updateAppWidget(appWidgetId, views)
}
Код: Выделить всё
Я пытался запустить виджет без добавленного кода, но он все равно не загружается.
Подробнее здесь: https://stackoverflow.com/questions/792 ... sonal-view
Мобильная версия