有人可以帮我翻译从java到kotlin吗? 我正在尝试制作Android小部件,当按下按钮时,它基本上会自动更新。
public class NewAppWidget extends AppWidgetProvider {
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
for (int appWidgetId : appWidgetIds) {
Intent intent1 = new Intent(context, NewAppWidget.class);
intent1.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
intent1.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
PendingIntent pendingIntent1 = PendingIntent.getBroadcast(context,0, intent1, 0);
RemoteViews remoteViews = new RemoteViews(context.getPackageName(),R.layout.new_app_widget);
remoteViews.setOnClickPendingIntent(R.id.buttonId, pendingIntent1);
//there will come my action
appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
}
}
}
有人可以为我翻译吗?
答案 0 :(得分:1)
Android Studio实际上可以为您将Java转换为Kotlin。按代码>将Java文件转换为Kotlin文件。