0

HI i am having right trouble handling a click on a widget! I have got it so I can print a message to logcat when it is clicked on but I cant say change the text of a textview or show a button.

My main goal is to get a button to become visible when clicking on the widget and from here open a settings menu or share options for social media.

Here is my On Update code (DaysTillWidget.class)

public void onUpdate(Context context, AppWidgetManager appWidgetManager,
                    int[] appWidgetIds) {
    for (int appWidgetId : appWidgetIds) {
            setAlarm(context, appWidgetId, UPDATE_RATE);
            RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.main);
            Intent clickIntent = new Intent(context, DaysTillWidget.class);
            clickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
            PendingIntent pendingIntent = PendingIntent.getBroadcast(context, appWidgetId, clickIntent, 0);
            views.setOnClickPendingIntent(R.id.imageView2, pendingIntent);
            appWidgetManager.updateAppWidget(appWidgetId, views);

        super.onUpdate(context, appWidgetManager, appWidgetIds);
    }

}

and here is the onRecieve code in the same Class

@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction()==null) {
    Bundle extras = intent.getExtras();
    if(extras!=null) {
        int widgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
        // do something for the widget that has appWidgetId = widgetId
        System.out.println("is this it?" + widgetId);
        RemoteViews RemoteViews = new RemoteViews(context.getPackageName(), R.layout.main);

    }
}
else {
    super.onReceive(context, intent);
 }
}

Any ideas on how I can get to my main goal?! I have spent hours reading peoples posts with similar problems but just cant get anything to work!

Im not sure if my project setup it correct or not but so far I have got everything else working? I have a service Class and a config class. If I cant get the button to show and hide I would like to relaunch the config activity with the sharedprefernces for that widgetId

If you need to see any more code please let me know Thanks in advance

3
  • The very last edit of the question here might help
    – TronicZomB
    Jun 17, 2013 at 20:20
  • Thanks. So i should create a new Reciever class to handle the PendingIntent? Sorry im quite new to all of this!
    – Alex
    Jun 18, 2013 at 6:52
  • That has helped me a great deal thanks! it was the appwidgetmanager part i needed that obv tells it to set the changes! Many thanks
    – Alex
    Jun 18, 2013 at 7:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.