Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>you need to rigister a reciver for widget click as in manifest :</p> <pre><code> &lt;receiver android:name="MyAppWidgetProvider" &gt; &lt;intent-filter&gt; &lt;action android:name="android.appwidget.action.APPWIDGET_UPDATE" /&gt; &lt;action android:name="com.myname.myapp.MyAppWidgetProvider.ACTION_CLICK" /&gt; &lt;/intent-filter&gt; &lt;meta-data android:name="android.appwidget.provider" android:resource="@xml/my_widget_info" /&gt; &lt;/receiver&gt; </code></pre> <p>AppWidgetProvider.java</p> <pre><code>public class MyAppWidgetProvider extends AppWidgetProvider { private static final String ACTION_CLICK = "ACTION_CLICK_WIDGET"; private final String widgetPageName = "_widget"; private static final String PREFS_NAME = "MYAPP"; private static final String PREF_PREFIX_KEY = "prefix_"; @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { ComponentName thisWidget = new ComponentName(context, MyAppWidgetProvider.class); final int N = appWidgetIds.length; for (int i=0; i&lt;N; i++) { int appWidgetId = appWidgetIds[i]; SharedPreferences myPrefs = context.getSharedPreferences(PREFS_NAME, context.MODE_WORLD_WRITEABLE); Integer objNum = myPrefs.getInt(PREF_PREFIX_KEY + appWidgetId, -1); if (objNum &gt; -1) { PageAction pa = (PageAction) CommonActivity .GetPageObjectAtIndex(context, widgetPageName, objNum); String majorLabel = pa.GetUnparsedMajorLabel(context).toString(); String minorLabel = pa.GetUnparsedMinorLabel(context).toString(); updateAppWidget(context, appWidgetManager, appWidgetId, majorLabel, minorLabel); } } } @Override public void onReceive(Context context, Intent intent) { String intentAction = intent.getAction(); if (intentAction.equals(ACTION_CLICK)) { updateWidgetState(paramContext, str); Bundle extras = intent.getExtras(); Integer appWidgetId = extras.getInt("appwidgetid"); SharedPreferences myPrefs = context.getSharedPreferences(PREFS_NAME, context.MODE_WORLD_WRITEABLE); Integer objNum = myPrefs.getInt(PREF_PREFIX_KEY + appWidgetId, -1); if (objNum &gt; -1) { PageAction pa = (PageAction) CommonActivity .GetPageObjectAtIndex(context, widgetPageName, objNum); pa.ExecuteActionFromWidgetClick(context); } } else { super.onReceive(context, intent); } } public static void updateWidgetState(Context paramContext, String paramString) { RemoteViews localRemoteViews = buildUpdate(paramContext, paramString); ComponentName localComponentName = new ComponentName(paramContext, MyAppWidgetProvider.class); AppWidgetManager.getInstance(paramContext).updateAppWidget(localComponentName, localRemoteViews); } private static RemoteViews buildUpdate(Context ctx, String paramString) { RemoteViews views = new RemoteViews(ctx.getPackageName(), R.layout.my_appwidget); views.setTextViewText(R.id.majorlabel, majorLabel); views.setTextViewText(R.id.minorlabel, minorLabel); Intent intent = new Intent(ctx, MyAppWidgetProvider.class); intent.setAction(ACTION_CLICK); intent.putExtra("appwidgetid", mAppWidgetId); PendingIntent configPendingIntentprev = PendingIntent.getBroadcast(ctx, 0, intent , 0); views.setOnClickPendingIntent(R.layout.my_appwidget, pendingIntent); if(parmString.equals(ACTION_CLICK)) { //Toast.maketext("").show(); // } return rview; } } </code></pre> <p>see my answer in <a href="https://stackoverflow.com/questions/10100217/how-to-find-which-button-has-been-clicked-in-app-widgets-in-android/10100739#10100739">this</a> post for full example.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload