'Button is not Worked at android widget
In the onUpdate function
RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.a_g_p_s_widget);
Intent it_1 = new Intent(context, Widget.class);
it_1.setAction(context.getResources().getString(R.string.ACTION_BTN_CHILD_1));
Intent it_2 = new Intent(context, Widget.class);
it_2.setAction(context.getResources().getString(R.string.ACTION_BTN_CHILD_2));
PendingIntent pdIt_1 = PendingIntent.getBroadcast(context, 0, it_1, 0);
PendingIntent pdIt_2 = PendingIntent.getBroadcast(context, 0, it_2, 0);
rv.setOnClickPendingIntent(R.id.btnFindChild_1, pdIt_1);
rv.setOnClickPendingIntent(R.id.btnFindChild_1, pdIt_2);
for (int appWidgetId : appWidgetIds) {
updateAppWidget(context, appWidgetManager, appWidgetId);
}
In the 'onReceive' function
String strAction = intent.getAction();
Toast.makeText(context, "onReceive event is occurred action = " + strAction, Toast.LENGTH_SHORT).show();
AppWidgetManager appMgr = AppWidgetManager.getInstance(context);
initUI(context, appMgr, appMgr.getAppWidgetIds(new ComponentName(context, getClass())));
if(strAction.equals(context.getResources().getString(R.string.ACTION_BTN_CHILD_1))){
Log.d(TAG, "Button 1 is clicked");
Toast.makeText(context, "Button 1 is clicked", Toast.LENGTH_SHORT).show();
} else if(strAction.equals(context.getResources().getString(R.string.ACTION_BTN_CHILD_2))){
Log.d(TAG, "Button 2 is clicked");
Toast.makeText(context, "Button 2 is clicked", Toast.LENGTH_SHORT).show();
} else{
Log.d(TAG, "No case");
}
This is my source code for the widget. But the button is not working. Please help! I didn't know why are not worked.
I have already added action to manifest file in my project. Other messages can receive. (Enable, update)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
