Titanium.Android.RemoteViews
> Titanium.Android.RemoteViews

The Titanium binding of Android RemoteViews.

RemoteViews is an API for referencing and updating a remote view hierarchy that lives in another process, for example, in a Notification.

To create a remote view hierarchy, you must define an Android XML layout for the views you want to display, and place the XML file in the platform/android/res/layout inside your project folder. See the examples for a sample XML layout and sample code for creating a remote view.

To use a remote view hierarchy in a notification, see Notification.contentView.

Because the remote view hierarchy belongs to another process, you cannot call methods on it directly, but you can call methods on the RemoteViews object to update views in the heirarchy by ID. To reference a view inside the layout, use the Titanium.App.Android.R object to reference the view's ID. For example, if you have a view with the ID notify_imageview, you can refer to it using:

Ti.App.Android.R.id.notify_imageview

See also:

Examples

Create a Remote View

The following code excerpt creates a RemoteViews object based on a custom layout called custom_layout.xml, and set a label's text.

var AppR = Ti.App.Android.R;
var customLayout = Ti.Android.createRemoteViews({ layoutId: AppR.layout.custom_layout });
customLayout.setTextViewText(AppR.id.custom_text, "Click Me!");

This example uses a simple custom layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:orientation="vertical" >
    <TextView android:id="@+id/custom_text"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="#ffffff"
            android:textColor="#aaff0000"
            android:textStyle="italic"
            android:gravity="center"
            android:text="Hello, I am a TextView" />
</LinearLayout>

The layout file for this example must be placed in platform/android/res/layout/custom_layout.xml.

  • 1.6
Defined By

Properties

apiName : Stringreadonly

The name of the API that this proxy corresponds to.

The name of the API that this proxy corresponds to.

The value of this property is the fully qualified name of the API. For example, Button returns Ti.UI.Button.

  • 3.2.0
  • 3.2.0
  • 3.2.0
Indicates if the proxy will bubble an event to its parent. ...

Indicates if the proxy will bubble an event to its parent.

Some proxies (most commonly views) have a relationship to other proxies, often established by the add() method. For example, for a button added to a window, a click event on the button would bubble up to the window. Other common parents are table sections to their rows, table views to their sections, and scrollable views to their views. Set this property to false to disable the bubbling to the proxy's parent.

Default: true

  • 3.0.0
  • 3.0.0
  • 3.0.0
Titanium.Android.RemoteViews
: NumberCreation-Only
Android layout resource ID for the view to display. ...

Android layout resource ID for the view to display. Required.

To define a custom layout resource in your application, the XML layout file should be placed in platform/android/res/layout folder inside your project folder.

Use Titanium.App.Android.R to reference the ID of the layout.

The Window or TabGroup whose Activity lifecycle should be triggered on the proxy.

The Window or TabGroup whose Activity lifecycle should be triggered on the proxy.

If this property is set to a Window or TabGroup, then the corresponding Activity lifecycle event callbacks will also be called on the proxy. Proxies that require the activity lifecycle will need this property set to the appropriate containing Window or TabGroup.

  • 3.6.0
Titanium.Android.RemoteViews
: StringCreation-Only
Package name that the resource ID lives in. ...

Package name that the resource ID lives in. Optional.

Defined By

Methods

Adds the specified callback as an event listener for the named event. ...

Adds the specified callback as an event listener for the named event.

Parameters

  • name : String

    Name of the event.

  • callback : Callback<Object>

    Callback function to invoke when the event is fired.

Returns

  • void
Applies the properties to the proxy. ...

Applies the properties to the proxy.

Properties are supplied as a dictionary. Each key-value pair in the object is applied to the proxy such that myproxy[key] = value.

  • 3.0.0
  • 3.0.0
  • 3.0.0

Parameters

  • props : Dictionary

    A dictionary of properties to apply.

Returns

  • void
Fires a synthesized event to any registered listeners. ...

Fires a synthesized event to any registered listeners.

Parameters

  • name : String

    Name of the event.

  • event : Dictionary

    A dictionary of keys and values to add to the Titanium.Event object sent to the listeners.

Returns

  • void
Gets the value of the apiName property. ...

Gets the value of the apiName property.

  • 3.2.0
  • 3.2.0
  • 3.2.0

Returns

  • String
Gets the value of the bubbleParent property. ...

Gets the value of the bubbleParent property.

  • 3.0.0
  • 3.0.0
  • 3.0.0

Returns

  • Boolean
Titanium.Android.RemoteViews
( ) : Number
Gets the value of the layoutId property. ...

Gets the value of the layoutId property.

Returns

  • Number
Gets the value of the lifecycleContainer property. ...

Gets the value of the lifecycleContainer property.

  • 3.6.0

Returns

Titanium.Android.RemoteViews
( ) : String
Gets the value of the packageName property. ...

Gets the value of the packageName property.

Returns

  • String
Removes the specified callback as an event listener for the named event. ...

Removes the specified callback as an event listener for the named event.

Multiple listeners can be registered for the same event, so the callback parameter is used to determine which listener to remove.

When adding a listener, you must save a reference to the callback function in order to remove the listener later:

var listener = function() { Ti.API.info("Event listener called."); }
window.addEventListener('click', listener);

To remove the listener, pass in a reference to the callback function:

window.removeEventListener('click', listener);

Parameters

  • name : String

    Name of the event.

  • callback : Callback<Object>

    Callback function to remove. Must be the same function passed to addEventListener.

Returns

  • void
Titanium.Android.RemoteViews
( viewId, methodName, value )
Calls a method taking a single boolean argument on a view in the remote view hierarchy. ...

Calls a method taking a single boolean argument on a view in the remote view hierarchy. See Android's documentation for setBoolean.

Parameters

  • viewId : Number

    Resource ID of the view to invoke the method on. Application-specific resource IDs can be specified using Titanium.App.Android.R.

  • methodName : String

    Name of the method to call.

  • value : Boolean

    Value to pass to the method.

Returns

  • void
Sets the value of the bubbleParent property. ...

Sets the value of the bubbleParent property.

  • 3.0.0
  • 3.0.0
  • 3.0.0

Parameters

  • bubbleParent : Boolean

    New value for the property.

Returns

  • void
Titanium.Android.RemoteViews
( viewId, base, format, started )
Sets the base time, format string, and started flag for a chronometer in the remote view hierarchy. ...

Sets the base time, format string, and started flag for a chronometer in the remote view hierarchy.

See Android's documentation for setChronometer.

Parameters

  • viewId : Number

    Resource ID of the Chronometer to update. Application-specific resource IDs can be specified using Titanium.App.Android.R.

  • base : Date

    Time at which the timer would have read 0:00.

  • format : String

    Chronometer format string, or null to simply display the timer value.

  • started : Boolean

    True if you want the clock to be started, false if not.

Returns

  • void
Titanium.Android.RemoteViews
( viewId, methodName, value )
Calls a method taking a single double argument on a view in the remote view hierarchy. ...

Calls a method taking a single double argument on a view in the remote view hierarchy.

See Android's documentation for setDouble.

Parameters

  • viewId : Number

    Resource ID of the view to update. Application-specific resource IDs can be specified using Titanium.App.Android.R.

  • methodName : String

    Name of the method to call.

  • value : Number

    Value to pass to the method.

Returns

  • void
Titanium.Android.RemoteViews
( viewId, srcId )
Sets the image for an image view in the remote view hierarchy using an Android drawable resource. ...

Sets the image for an image view in the remote view hierarchy using an Android drawable resource.

See Android's documentation for setImageViewResource.

Parameters

  • viewId : Number

    Resource ID of the ImageView to update. Application-specific resource IDs can be specified using Titanium.App.Android.R.

  • srcId : Number

    Resource ID of the new image. Application-specific resource IDs can be specified using Titanium.App.Android.R.

Returns

  • void
Titanium.Android.RemoteViews
( viewId, uri )
Sets the image for an image view in the remote view hierarchy using a URI. ...

Sets the image for an image view in the remote view hierarchy using a URI.

This method supports supports both Android and Titanium URLs.

See Android's documentation for setImageViewUri.

Parameters

  • viewId : Number

    Resource ID of the ImageView to update. Application-specific resource IDs can be specified using Titanium.App.Android.R.

  • uri : String

    URI of the image (both Android and Titanium URLs are supported).

Returns

  • void
Titanium.Android.RemoteViews
( viewId, methodName, value )
Calls a method taking a single int argument on a view in the remote view hierarchy. ...

Calls a method taking a single int argument on a view in the remote view hierarchy.

See Android's documentation for setInt

Parameters

  • viewId : Number

    Resource ID of the view to update. Application-specific resource IDs can be specified using Titanium.App.Android.R.

  • methodName : String

    Name of the method to call.

  • value : Number

    Value to pass to the method.

Returns

  • void
Titanium.Android.RemoteViews
( layoutId )
Sets the value of the layoutId property. ...

Sets the value of the layoutId property.

Parameters

  • layoutId : Number

    New value for the property.

Returns

  • void
Sets the value of the lifecycleContainer property. ...

Sets the value of the lifecycleContainer property.

  • 3.6.0

Parameters

Returns

  • void
Titanium.Android.RemoteViews
( viewId, pendingIntent )
Launches a Titanium.Android.PendingIntent when the specified view is clicked. ...

Launches a Titanium.Android.PendingIntent when the specified view is clicked.

See Android's documentation for setOnClickPendingIntent.

Parameters

Returns

  • void
Titanium.Android.RemoteViews
( packageName )
Sets the value of the packageName property. ...

Sets the value of the packageName property.

Parameters

  • packageName : String

    New value for the property.

Returns

  • void
Titanium.Android.RemoteViews
( viewId, max, progress, indeterminate )
Sets the progress, max value, and indeterminate flag of a progress bar in the remote view hierarchy. ...

Sets the progress, max value, and indeterminate flag of a progress bar in the remote view hierarchy.

See Android's documentation for setProgressBar.

Parameters

  • viewId : Number

    Resource ID of the progress bar to update. Application-specific resource IDs can be specified using Titanium.App.Android.R.

  • max : Number

    The new maximum value of the progress bar.

  • progress : Number

    The new progress value of the progress bar (from 0..max).

  • indeterminate : Boolean

    Determines whether the progress bar is indeterminate. If true, the progress bar displays an infinite looping animation.

Returns

  • void
Titanium.Android.RemoteViews
( viewId, methodName, value )
Calls a method taking a single String argument on a view in the remote view hierarchy. ...

Calls a method taking a single String argument on a view in the remote view hierarchy.

See Android's documentation for setString.

Parameters

  • viewId : Number

    Resource ID of the view to update. Application-specific resource IDs can be specified using Titanium.App.Android.R.

  • methodName : String

    Name of the method to call.

  • value : String

    String to pass to the method.

Returns

  • void
Titanium.Android.RemoteViews
( viewId, color )
Sets the text color of a view in the remote view hierarchy. ...

Sets the text color of a view in the remote view hierarchy.

See Android's documentation for setTextColor.

Parameters

  • viewId : Number

    Resource ID of the view to update. Application-specific resource IDs can be specified using Titanium.App.Android.R.

  • color : Number

    Color as an integer.

Returns

  • void
Titanium.Android.RemoteViews
( viewId, text )
Sets the text of a text view in the remote view hierarchy. ...

Sets the text of a text view in the remote view hierarchy.

See Android's documentation for setTextViewText.

Parameters

  • viewId : Number

    Resource ID of the text view to update. Application-specific resource IDs can be specified using Titanium.App.Android.R.

  • text : String

    New text for the text view.

Returns

  • void
Titanium.Android.RemoteViews
( viewId, methodName, value )
Calls a method taking one URI on a view in the remote view hierarchy. ...

Calls a method taking one URI on a view in the remote view hierarchy.

See Android's documentation for setUri.

Parameters

  • viewId : Number

    Resource ID of the view to update. Application-specific resource IDs can be specified using Titanium.App.Android.R.

  • methodName : String

    Name of the method to call.

  • value : String

    URI (as a string) to pass to the method.

Returns

  • void
Titanium.Android.RemoteViews
( viewId, visibility )
Sets the visibility of a view in the remote view hierarchy. ...

Sets the visibility of a view in the remote view hierarchy.

See Android's documentation for setViewVisibility

Parameters

  • viewId : Number

    Resource ID of the view to show or hide. Application-specific resource IDs can be specified using Titanium.App.Android.R.

  • visibility : Number

    The visibility. Either 0 (VISIBLE), 4 (INVISIBLE) or 8 (GONE).

Returns

  • void