Please help with very simple android widget button click. Getting very frustrated. :(

Posted by Little Wendy on Stack Overflow See other posts from Stack Overflow or by Little Wendy
Published on 2011-02-10T23:22:49Z Indexed on 2011/02/10 23:25 UTC
Read the original article Hit count: 148

Filed under:
|
|
|
|

I have poured over every example that I can find and I have gone through the official documentation from google. All I am trying to do is create a toast notification from a button click on a widget.

I can get the widget (and button) to appear but I can't get my intent to fire. I have seen several examples that show doing this different ways but I just can't get it to work. I haven't felt this helpless with coding in a long time and I'm starting to feel dumb.

This is what I have so far:

public class simpleclick extends AppWidgetProvider {
    /** Called when the activity is first created. */

    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
        final int N = appWidgetIds.length;

        Toast.makeText(context, "doing on update", Toast.LENGTH_SHORT).show();

        for (int i=0; i<N; i++) {

            int appWidgetId = appWidgetIds[i];

            Intent intent = new Intent(context, simpleclick.class);
            intent.setAction("ham");
            PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);

            RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.main);
            views.setOnClickPendingIntent(R.id.Timm, pendingIntent);

            appWidgetManager.updateAppWidget(appWidgetId, views);

        }

    }

    //@Override
    public void onReceive(Context context, Intent intent) {
     // TODO Auto-generated method stub

     Toast.makeText(context, "action is: " + intent.getAction(), Toast.LENGTH_SHORT).show();

     super.onReceive(context, intent);

    }

}

My manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.tblabs.simpleclick"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <receiver android:name="simpleclick">
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
        </intent-filter>
        <meta-data android:name="android.appwidget.provider" 
            android:resource="@xml/simpleclick" />
        </receiver>

    </application>
    <uses-sdk android:minSdkVersion="5" />

</manifest> 

I would appreciate some help!

Thanks, Wendy

© Stack Overflow or respective owner

Related posts about android

Related posts about button