I create an appwidget with a listview. In RemoteViewsFactory class I'm populate list from SQLite database. All is fine, but if I put a one string in updateWidget() method than I get IndexOutOfBoundsException in a getViewAt method of RemoteViewsFactory.
It's has no logic why it cause Exception. Because in updateWidget() method I only set text to one remoteview.
Here a code list and string that cause a problem:
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId)
{
SharedPreferences sPreferences = context.getSharedPreferences("WidgetSettings_"+appWidgetId,0);
RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.initial_layout);
DBHelper dbHelper = DBHelper.getInstance(context);
// To avoid Exception in a RemoteViewsFactory.getViewAt() method just comment or delete this line
rv.setTextViewText(R.id.textViewListTotal, "Total sum of items"); // this line cause an Exception. If I commenting it then all is OK
final Intent intent = new Intent(context, WidgetRemoteViewsService.class);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
rv.setRemoteAdapter(appWidgetId, R.id.items_list, intent);
rv.setEmptyView(R.id.items_list, R.id.empty_view);
final Intent actionIntent = new Intent(context, WidgetProvider.class);
actionIntent.setAction(WidgetProvider.ACTION_MANAGE);
actionIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
actionIntent.setData(Uri.parse(actionIntent.toUri(Intent.URI_INTENT_SCHEME)));
PendingIntent actionPendingIntent = PendingIntent.getBroadcast(context, 0, actionIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
rv.setPendingIntentTemplate(R.id.items_list, actionPendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, rv);
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetId, R.id.items_list);
}