# Titanium.Android.RemoteViews

> The Titanium binding of [Android RemoteViews](https://developer.android.com/reference/android/widget/RemoteViews.html).

- Source: https://titaniumsdk.com/docs/sdk/12.5.0/Titanium.Android.RemoteViews
- Titanium SDK version: 12.5.0
- Kind: proxy
- Platforms: Android
- Since: Titanium SDK 1.6
- Extends: Titanium.Proxy
- Inheritance: Titanium.Proxy

`RemoteViews` is an API for referencing and updating a remote view hierarchy that
lives in another process, for example, in a [Notification](https://titaniumsdk.com/docs/sdk/Titanium.Android.Notification.md).

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](https://titaniumsdk.com/docs/sdk/Titanium.Android.Notification.md#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](https://titaniumsdk.com/docs/sdk/Titanium.App.Android.md#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:
    
``` js
Ti.App.Android.R.id.notify_imageview
```

See also: 

*   [RemoteViews](https://developer.android.com/reference/android/widget/RemoteViews.html)
    in the Android Developer Reference.

*   [XML Layouts](https://developer.android.com/guide/topics/ui/declaring-layout.html)
    in the Android Developer Guide.

## Example: 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.

``` js
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
<?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`.

## Properties

### layoutId

- Type: Number
- Platforms: Android

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](https://titaniumsdk.com/docs/sdk/Titanium.App.Android.md#R) to reference the ID of the layout.

### packageName

- Type: String
- Platforms: Android

Package name that the resource ID lives in. Optional.

## Methods

### setBoolean

- Platforms: Android

Calls a method taking a single `boolean` argument on a view in the remote view
hierarchy.  See Android's documentation for
[setBoolean](https://developer.android.com/reference/android/widget/RemoteViews.html#setBoolean(int, java.lang.String, boolean)).

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](https://titaniumsdk.com/docs/sdk/Titanium.App.Android.md#R).
- `methodName` (String): Name of the method to call.
- `value` (Boolean): Value to pass to the method.

### setChronometer

- Platforms: Android

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

See Android's documentation for 
[setChronometer](https://developer.android.com/reference/android/widget/RemoteViews.html#setChronometer(int, long, java.lang.String, boolean)).

Parameters:

- `viewId` (Number): Resource ID of the Chronometer to update. Application-specific resource IDs can be specified using [Titanium.App.Android.R](https://titaniumsdk.com/docs/sdk/Titanium.App.Android.md#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.

### setDouble

- Platforms: Android

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

See Android's documentation for 
[setDouble](https://developer.android.com/reference/android/widget/RemoteViews.html#setDouble(int, java.lang.String, double)).

Parameters:

- `viewId` (Number): Resource ID of the view to update. Application-specific resource IDs can be specified using [Titanium.App.Android.R](https://titaniumsdk.com/docs/sdk/Titanium.App.Android.md#R).
- `methodName` (String): Name of the method to call.
- `value` (Number): Value to pass to the method.

### setImageViewResource

- Platforms: Android

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

See Android's documentation for 
[setImageViewResource](https://developer.android.com/reference/android/widget/RemoteViews.html#setImageViewResource(int, int)).

Parameters:

- `viewId` (Number): Resource ID of the `ImageView` to update. Application-specific resource IDs can be specified using [Titanium.App.Android.R](https://titaniumsdk.com/docs/sdk/Titanium.App.Android.md#R).
- `srcId` (Number): Resource ID of the new image. Application-specific resource IDs can be specified using [Titanium.App.Android.R](https://titaniumsdk.com/docs/sdk/Titanium.App.Android.md#R).

### setImageViewUri

- Platforms: Android

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](https://developer.android.com/reference/android/widget/RemoteViews.html#setImageViewUri(int, android.net.Uri)).

Parameters:

- `viewId` (Number): Resource ID of the `ImageView` to update. Application-specific resource IDs can be specified using [Titanium.App.Android.R](https://titaniumsdk.com/docs/sdk/Titanium.App.Android.md#R).
- `uri` (String): URI of the image (both Android and Titanium URLs are supported).

### setInt

- Platforms: Android

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

See Android's documentation for [setInt](https://developer.android.com/reference/android/widget/RemoteViews.html#setInt(int, java.lang.String, int))

Parameters:

- `viewId` (Number): Resource ID of the view to update. Application-specific resource IDs can be specified using [Titanium.App.Android.R](https://titaniumsdk.com/docs/sdk/Titanium.App.Android.md#R).
- `methodName` (String): Name of the method to call.
- `value` (Number): Value to pass to the method.

### setOnClickPendingIntent

- Platforms: Android

Launches a [Titanium.Android.PendingIntent](https://titaniumsdk.com/docs/sdk/Titanium.Android.PendingIntent.md) when the specified view is clicked.

See Android's documentation for
[setOnClickPendingIntent](https://developer.android.com/reference/android/widget/RemoteViews.html#setOnClickPendingIntent(int, android.app.PendingIntent)).

Parameters:

- `viewId` (Number): Resource ID of the view to add a click listener to. Application-specific resource IDs can be specified using [Titanium.App.Android.R](https://titaniumsdk.com/docs/sdk/Titanium.App.Android.md#R).
- `pendingIntent` (Titanium.Android.PendingIntent): The `PendingIntent` to execute when this view is clicked.

### setProgressBar

- Platforms: Android

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

See Android's documentation for
[setProgressBar](https://developer.android.com/reference/android/widget/RemoteViews.html#setProgressBar(int, int, int, boolean)).

Parameters:

- `viewId` (Number): Resource ID of the progress bar to update. Application-specific resource IDs can be specified using [Titanium.App.Android.R](https://titaniumsdk.com/docs/sdk/Titanium.App.Android.md#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.

### setString

- Platforms: Android

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

See Android's documentation for
[setString](https://developer.android.com/reference/android/widget/RemoteViews.html#setString(int, java.lang.String, java.lang.String)).

Parameters:

- `viewId` (Number): Resource ID of the view to update. Application-specific resource IDs can be specified using [Titanium.App.Android.R](https://titaniumsdk.com/docs/sdk/Titanium.App.Android.md#R).
- `methodName` (String): Name of the method to call.
- `value` (String): String to pass to the method.

### setTextColor

- Platforms: Android

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

See Android's documentation for
[setTextColor](https://developer.android.com/reference/android/widget/RemoteViews.html#setTextColor(int, int)).

Parameters:

- `viewId` (Number): Resource ID of the view to update. Application-specific resource IDs can be specified using [Titanium.App.Android.R](https://titaniumsdk.com/docs/sdk/Titanium.App.Android.md#R).
- `color` (Number): Color as an integer.

### setTextViewText

- Platforms: Android

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

See Android's documentation for
[setTextViewText](https://developer.android.com/reference/android/widget/RemoteViews.html#setTextViewText(int, java.lang.CharSequence)).

Parameters:

- `viewId` (Number): Resource ID of the text view to update. Application-specific resource IDs can be specified using [Titanium.App.Android.R](https://titaniumsdk.com/docs/sdk/Titanium.App.Android.md#R).
- `text` (String): New text for the text view.

### setUri

- Platforms: Android

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

See Android's documentation for
[setUri](https://developer.android.com/reference/android/widget/RemoteViews.html#setUri(int, java.lang.String, android.net.Uri)).

Parameters:

- `viewId` (Number): Resource ID of the view to update. Application-specific resource IDs can be specified using [Titanium.App.Android.R](https://titaniumsdk.com/docs/sdk/Titanium.App.Android.md#R).
- `methodName` (String): Name of the method to call.
- `value` (String): URI (as a string) to pass to the method.

### setViewVisibility

- Platforms: Android

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

See Android's documentation for [setViewVisibility](https://developer.android.com/reference/android/widget/RemoteViews.html#setViewVisibility(int, int))

Parameters:

- `viewId` (Number): Resource ID of the view to show or hide. Application-specific resource IDs can be specified using [Titanium.App.Android.R](https://titaniumsdk.com/docs/sdk/Titanium.App.Android.md#R).
- `visibility` (Number): The visibility. Either `0` (VISIBLE), `4` (INVISIBLE) or `8` (GONE).

## Inherited members

7 members are inherited. Each is documented on the type that declares it.

- [Titanium.Proxy](https://titaniumsdk.com/docs/sdk/12.5.0/Titanium.Proxy.md): `addEventListener`, `apiName`, `applyProperties`, `bubbleParent`, `fireEvent`, `lifecycleContainer`, `removeEventListener`

---

- This corpus documents Titanium SDK 13.4.1. Anything here that does not name a version describes 13.4.1.
- Titanium is maintained by TiDev. The Appcelerator toolchain is retired: there is no `appc` CLI, no Appcelerator Studio and no hosted build service. The supported CLI is `titanium` on npm, invoked as `ti`.

