user444186
user444186

Reputation: 11

Android Widget, not clickable

I am new to Android Dev, and this is my first widget.

What is supposed to happen is when the user clicks the widget, it turns off or on the Master Sync option.

However the widget does not do anything when clicked, and appears to not be clickable.

This is the body of the .java code, if it helps to post any of the other code please let me know.

public class MasterSync extends AppWidgetProvider {
    /** Called when the activity is first created. */
    @Override

    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {

     final int N = appWidgetIds.length;

        // now label the property of the button
     boolean sync = ContentResolver.getMasterSyncAutomatically();

  if (sync){  

    ContentResolver.setMasterSyncAutomatically(false);}
  else

  if (!sync){

     ContentResolver.setMasterSyncAutomatically(true);
    }

    }}

Upvotes: 1

Views: 1749

Answers (3)

MegaMind
MegaMind

Reputation: 336

onUpdate is called when the widget is run for the first time or after every specified time interval as mentioned in the xml. In order to handle the click event of a button you can use PendingIntents. You need to register your broadcast action on click of a button with the PendingIntent and then inside your onReceive() you can write your logic to handle the broadcast which will be fired when button is clicked.

Refer this article for code snippet.

Upvotes: 1

Ran
Ran

Reputation: 4157

onUpdate is called when the widget is updated, not when clicked

Upvotes: 0

DonGru
DonGru

Reputation: 13710

processing a click on a widget takes a bit more than just one line of code - have a look at this tutorial - it explains the basics of widgets and also how to process clicks:

Hello Widget Tutorial

Upvotes: 3

Related Questions