It is possible to make an onClick event for Views in Widgets. You can create as many onClick events as you want.
On top of your Widget class, create a static variable, which will be your onClick name tag:
private static final String MyOnClick = "myOnClickTag";
Define a helper method to automate the creation of each PendingIntent
:
protected PendingIntent getPendingSelfIntent(Context context, String action) {
Intent intent = new Intent(context, getClass());
intent.setAction(action);
return PendingIntent.getBroadcast(context, 0, intent, 0);
}
Set this onClick tag to your view as below:
remoteViews.setOnClickPendingIntent(R.id.button,
getPendingSelfIntent(context, MyOnClick));
create an onReceive method in your Widget class and set this onClick event inside it:
public void onReceive(Context context, Intent intent) {
if (MyOnClick.equals(intent.getAction())){
//your onClick action is here
}
};
Whenever the view that you set the tag is pressed, onReceive will capture that and will do the action just the same as our everyday, standard onClick event.
Edit: According to your answer, can you replace your onUpdate content with following lines and try again:
RemoteViews remoteViews = new RemoteViews(context.getPackageName(),R.layout.widget_det);
thisWidget = new ComponentName(context, MyWidgetProvider.class);
remoteViews.setOnClickPendingIntent(R.id.widget_button_stayarm, getPendingSelfIntent(context, MyOnClick1));
remoteViews.setOnClickPendingIntent(R.id.widget_button_awayarm, getPendingSelfIntent(context, MyOnClick2));
remoteViews.setOnClickPendingIntent(R.id.widget_button_dissarm, getPendingSelfIntent(context, MyOnClick3));
remoteViews.setTextViewText(R.id.widget_textview_gpscoords, "gps cords");
appWidgetManager.updateAppWidget(thisWidget, remoteViews);