Note that there are some explanatory texts on larger screens.

plurals
  1. POScrollable widget not filled
    text
    copied!<p>I tried to get a resizeable widget working, but it won't. I've got a database which I use with greenDAO. So my app should work on Android 2.3+. That's why I want to have got the following widgets:</p> <ul> <li>4x2 with 2 items</li> <li>4x3 with 3 items</li> <li>4x4 with 4 items</li> <li>4x5 with 5 items</li> </ul> <p>In preHoneycomb these <code>Widgets</code> should just show the first items and opens the app on click.</p> <p>In Android 3+ these <code>widgets</code> should be realizable and scrollable. My problem is that my Widget Service class is never called. So nothing inside the widget will be filled :-</p> <p>Here is my code:</p> <pre><code>public class WidgetProvider extends AppWidgetProvider { private static final String TAG = "WidgetProvider"; @TargetApi(14) @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { Log.i(TAG, "Update!!"); for (int i = 0; i &lt; appWidgetIds.length; ++i) { int appWidgetId = appWidgetIds[i]; Intent intent = new Intent(context, TimetableActivity_.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); Intent svcIntent = new Intent(context, WidgetService.class); svcIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]); svcIntent.setData(Uri.parse(svcIntent .toUri(Intent.URI_INTENT_SCHEME))); RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget); views.setOnClickPendingIntent(R.id.img_widget_home, pendingIntent); views.setRemoteAdapter(R.id.btn_widget_refresh, svcIntent); Intent update = new Intent(context, WidgetProvider.class); intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds); PendingIntent pend = PendingIntent.getBroadcast(context, 0, update, PendingIntent.FLAG_UPDATE_CURRENT); views.setOnClickPendingIntent(R.id.btn_widget_refresh, pend); appWidgetManager.updateAppWidget(appWidgetId, views); } super.onUpdate(context, appWidgetManager, appWidgetIds); } @TargetApi(11) public class WidgetService extends RemoteViewsService { private static final String TAG = "WidgetService"; @Override public RemoteViewsFactory onGetViewFactory(Intent intent) { Log.i(TAG, "WidgetService called"); return new ListRemoteViewsFactory(this.getApplicationContext(), (TimetableApplication_) this.getApplication(), intent); } } class ListRemoteViewsFactory implements RemoteViewsService.RemoteViewsFactory { private static final String TAG = "ListRemoteViewsFactory"; private Context mContext; private TimetableApplication_ application; private List&lt;Events&gt; events = new ArrayList&lt;Events&gt;(); public ListRemoteViewsFactory(Context context, TimetableApplication_ application, Intent intent) { this.mContext = context; this.application = application; } public int getCount() { return events.size(); } public RemoteViews getViewAt(int position) { Log.i(TAG, ""+getCount()); String title = ""; String description = ""; Events e; if ((e = events.get(position)) != null) { title = e.getSubjects().getTitle(); description = e.getStart().toGMTString(); } RemoteViews rv = new RemoteViews(mContext.getPackageName(), R.layout.widget_item); rv.setTextViewText(R.id.txt_widget_item_title, title); rv.setTextViewText(R.id.txt_widget_item_description, description); return rv; } public RemoteViews getLoadingView() { return null; } public int getViewTypeCount() { return 1; } public long getItemId(int position) { return position; } public boolean hasStableIds() { return true; } public void onDataSetChanged() { if (events != null) { events.clear(); } events = application.getEvents(); } @Override public void onCreate() { } @Override public void onDestroy() { } } </code></pre> <p>And here is my Manifest file:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="de.mprengemann.hwr.timetabel" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="9" android:targetSdkVersion="15" /&gt; &lt;uses-permission android:name="android.permission.INTERNET" /&gt; &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt; &lt;uses-permission android:name="android.permission.GET_ACCOUNTS" /&gt; &lt;uses-permission android:name="android.permission.READ_CALENDAR" /&gt; &lt;uses-permission android:name="android.permission.WRITE_CALENDAR" /&gt; &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt; &lt;application android:name=".TimetableApplication_" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/TimetableTheme" &gt; &lt;activity android:name=".TimetableActivity_" android:label="@string/app_name" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;activity android:name=".PreferenceActivity_" android:label="@string/menu_settings" &gt; &lt;/activity&gt; &lt;activity android:name=".SubjectDetailActivity_" &gt; &lt;/activity&gt; &lt;receiver android:name=".widget.WidgetProvider" &gt; &lt;intent-filter&gt; &lt;action android:name="android.appwidget.action.APPWIDGET_UPDATE" /&gt; &lt;/intent-filter&gt; &lt;meta-data android:name="android.appwidget.provider" android:resource="@xml/widgetprovider" /&gt; &lt;/receiver&gt; &lt;service android:name=".widget.WidgetService" /&gt; &lt;service android:name=".widget.ListWidgetService" /&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre> <p>Thanks for your help! :-)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload