I need to get the id of the AppWidget
when I click on it because I need the value to correctly perform certain action have some way to do it in a scalable way? but getting the id of the appwidget that I clicked is already a big help
I use a code to fetch all ids
But I can not get what I need that's what I clicked on
public class AppWidget extends AppWidgetProvider {
private static final String MontWidget = "WidgetPreferences";
private static String ID_CONFIG_WIDGET = "teste_config";
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
int appWidgetId) {
RemoteViews views;
SharedPreferences dados = context.getSharedPreferences(MontWidget, 0);
Integer posicao = dados.getInt(ID_CONFIG_WIDGET+appWidgetId, 0);
Log.i("Posicao de selecao", String.valueOf(posicao));
if (posicao == 0) {
CharSequence widgetText = Widget_Config.loadTitlePref(context, appWidgetId);
views = new RemoteViews(context.getPackageName(), R.layout.x1);
Intent confirmar_acao = new Intent(context, Alert_x1_Activity.class);
confirmar_acao.putExtra(Alert_x1_Activity.ARG_DIALOG_NUMBER, 1);
confirmar_acao.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent confirmar_acao_u = PendingIntent.getActivity(context,
0, confirmar_acao, PendingIntent.FLAG_UPDATE_CURRENT);
views.setOnClickPendingIntent(R.id.btn_X1, confirmar_acao_u);
views.setOnClickPendingIntent(R.id.txt_x1, confirmar_acao_u);
views.setTextViewText(R.id.txt_x1,widgetText);
appWidgetManager.updateAppWidget(appWidgetId, views);
}
if (posicao == 1) {
CharSequence widgetText = Widget_Config.loadTitlePref(context, appWidgetId);
views = new RemoteViews(context.getPackageName(), R.layout.x2);
Intent confirmar_acao = new Intent(context, Alert_x2_Activity.class);
confirmar_acao.putExtra(Alert_x2_Activity.ARG_DIALOG_NUMBER, 1);
confirmar_acao.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent confirmar_acao_u = PendingIntent.getActivity(context,
0, confirmar_acao, PendingIntent.FLAG_UPDATE_CURRENT);
views.setOnClickPendingIntent(R.id.btn_x2, confirmar_acao_u);
views.setOnClickPendingIntent(R.id.txt_x2, confirmar_acao_u);
views.setTextViewText(R.id.txt_x2,widgetText);
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
System.out.println("onUpdate");
final int N = appWidgetIds.length;
RemoteViews views;
for (int i=0; i<N; i++) {
int appWidgetId = appWidgetIds[i];
Intent intent = new Intent(context, Alert_x1_Activity.class);
intent.putExtra("KEY_ID",appWidgetId);
PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, intent, 0);
// Get the layout for the App Widget and attach an on-click listener
// to the button
views = new RemoteViews(context.getPackageName(), R.layout.x1_widget);
views.setOnClickPendingIntent(R.id.btn_x1, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}