Here is my solution for my own Problem:
I created an PendingIntent to listen to the button.
remoteviews.setOnClickPendingIntent(R.id.refresh_btn,
getPendingSelfIntent(context, BTN_REFRESH));
protected PendingIntent getPendingSelfIntent(Context context, String action) {
Intent intent = new Intent(context, getClass());
intent.setAction(action);
return PendingIntent.getBroadcast(context, 0, intent, 0);
}
I use global toggleState and call a method:
private void refresh(RemoteViews remoteviews, Context context) {
if (toggleState) {//if Button gets clicked onReceive will update all widgets
remoteviews.setViewVisibility(R.id.refresh_btn, View.GONE);
remoteviews.setViewVisibility(R.id.refresh_btn_rev, View.VISIBLE);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
toggleState = false;
updateAllWidgets(context);
}
}, 500);
} else {
remoteviews.setViewVisibility(R.id.refresh_btn, View.VISIBLE);
remoteviews.setViewVisibility(R.id.refresh_btn_rev, View.GONE);
}
}
toggleState is set to true if Button gets clicked.