Code example for RemoteViews

Methods: setOnClickPendingIntent, setTextViewText

0
            message = getResources().getText(res).toString();
        } 
        if (mRemoteViews == null || mRemoteViews.getLayoutId() != mRAlertLayout) {
            mRemoteViews = getRemoteView(mRAlertLayout);
        } 
        mRemoteViews.setTextViewText(mRAlertMessage, message);
        mManager.updateAppWidget(mWidget, mRemoteViews);
        Log.d("Widget.displayAlert", "Alert displayed with message: "+message);
 
    } 
 
    public void displayLoader(String message) {
        if (mRLoaderLayout == 0) {
            mRLoaderLayout = getResources().getIdentifier("widget_loader", "layout", getPackageName());
            mRLoaderMessage = getResources().getIdentifier("loadermessage", "id", getPackageName());
        } 
        if (message == null || message.length() == 0) {
            int res = getResources().getIdentifier("widget_loader", "string", getPackageName());
            message = getResources().getText(res).toString();
        } 
        if (mRemoteViews == null || mRemoteViews.getLayoutId() != mRLoaderLayout) {
            mRemoteViews = getRemoteView(mRLoaderLayout);
        } 
        mRemoteViews.setTextViewText(mRLoaderMessage, message);
        mManager.updateAppWidget(mWidget, mRemoteViews);
        Log.d("Widget.displayAlert", "Loader displayed with message: "+message);
    } 
 
    private RemoteViews getRemoteView (int layout) {
        RemoteViews rv = new RemoteViews(getPackageName(), layout);
 
        // When user clicks on widget, go fullscreen 
        Intent intent = new Intent(this, MainActivity.class);
        PendingIntent pendingIntent = PendingIntent
                .getActivity(this, 0, intent, 0);
        rv.setOnClickPendingIntent(mRWidget, pendingIntent);
        return rv;
    } 
}