Example usage for android.widget RemoteViews setEmptyView

List of usage examples for android.widget RemoteViews setEmptyView

Introduction

In this page you can find the example usage for android.widget RemoteViews setEmptyView.

Prototype

public void setEmptyView(int viewId, int emptyViewId) 

Source Link

Document

Equivalent to calling AdapterView#setEmptyView(View)

Usage

From source file:com.ravi.apps.android.newsbytes.widget.NewsWidgetProvider.java

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    Log.d(LOG_TAG, context.getString(R.string.log_on_update));

    // Update each app widget instance with remote view and corresponding remote adapter.
    for (int appWidgetId : appWidgetIds) {
        // Create the remote views object for the widget instance.
        RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.widget_news);

        // Create the intent that starts the service which will provide the views for this collection.
        Intent serviceIntent = new Intent(context, NewsWidgetRemoteViewsService.class);

        // Add the app widget id to the intent extras.
        serviceIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
        serviceIntent.setData(Uri.parse(serviceIntent.toUri(Intent.URI_INTENT_SCHEME)));

        // Set the remote adapter onto the scores list view in the remote view.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            remoteView.setRemoteAdapter(R.id.widget_list_view, serviceIntent);
        } else {//from ww  w  .  j a v a 2 s.  c om
            remoteView.setRemoteAdapter(appWidgetId, R.id.widget_list_view, serviceIntent);
        }

        // Create an intent to launch the main activity and set it on the remote view's title.
        Intent intent = new Intent(context, MainActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
        remoteView.setOnClickPendingIntent(R.id.widget, pendingIntent);

        // Create and add the list item click pending intent template.
        Intent listItemClickIntent = new Intent(context, MainActivity.class);
        listItemClickIntent.setAction(context.getString(R.string.action_item_clicked))
                .setData(Uri.parse(listItemClickIntent.toUri(Intent.URI_INTENT_SCHEME)));

        // Set the pending intent template.
        PendingIntent clickPendingIntentTemplate = TaskStackBuilder.create(context)
                .addNextIntentWithParentStack(listItemClickIntent)
                .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
        remoteView.setPendingIntentTemplate(R.id.widget_list_view, clickPendingIntentTemplate);

        // Set an empty view in case of no data.
        remoteView.setEmptyView(R.id.widget_list_view, R.id.widget_empty);

        // Call app widget manager to update the app widget instance.
        appWidgetManager.updateAppWidget(appWidgetId, remoteView);
    }

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