J'ai un widget qui affiche un texte simple et 3 boutons:Gérer plusieurs boutons à l'intérieur d'un widget - Android
- Actualiser (Ramasse une autre chaîne aléatoire et l'affiche)
- Copier (Copiez le contenu du textview le presse-papiers)
- Share (Partager le contenu du textview aux médias sociaux et autres)
je déjà obtenu la configuration du bouton de rafraîchissement et fonctionne très bien, mais je ne peux pas sembler trouver un moyen pour gérer les deux autres boutons
PS. Je ne veux pas le code actuel, je sais déjà comment faire la copie et le partage j'ai juste besoin de savoir comment gérer les événements cliquez
Voici mon code à ce jour:
Button copy_content;
Button share_content;
void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
/** Code below will be executed once the timer is over*/
String widgetText = RandQuotes[rand.nextInt(RandQuotes.length)];
// Construct the RemoteViews object
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.quotes_widget);
views.setTextViewText(R.id.sayings, widgetText);
// Instruct the widget manager to update the widget
appWidgetManager.updateAppWidget(appWidgetId, views);
}
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
// There may be multiple widgets active, so update all of them
for (int appWidgetId : appWidgetIds) {
updateAppWidget(context, appWidgetManager, appWidgetId);
}
final int count = appWidgetIds.length;
for (int i = 0; i < count; i++) {
int widgetId = appWidgetIds[i];
String on_sayings = RandQuotes[rand.nextInt(RandQuotes.length)];
RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
R.layout.quotes_widget);
remoteViews.setTextViewText(R.id.sayings, on_sayings);
Intent intent = new Intent(context, HavamalWidget.class);
intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.switch_trigger, pendingIntent);
appWidgetManager.updateAppWidget(widgetId, remoteViews);
}
}
Je me suis perdu en suivant vos instructions, pouvez-vous poster la réponse complète s'il vous plaît? –
il suffit de cocher réponse à nouveau –
j'ai quelques problèmes avec 'CommonRemoteViewBuilder' et les boutons d'action' 'ACTION_BUTTON_COPY' et ACTION_BUTTON_REFRESH' est dit « ne peut pas résoudre le symbole » –