diff options
Diffstat (limited to 'core/java/android/widget/RemoteViews.java')
| -rw-r--r-- | core/java/android/widget/RemoteViews.java | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/core/java/android/widget/RemoteViews.java b/core/java/android/widget/RemoteViews.java index dfb2263a97a7..2328e589216b 100644 --- a/core/java/android/widget/RemoteViews.java +++ b/core/java/android/widget/RemoteViews.java @@ -358,6 +358,13 @@ public class RemoteViews implements Parcelable, Filter { @ApplyFlags private int mApplyFlags = 0; + /** + * Id to use to override the ID of the top-level view in this RemoteViews. + * + * Only used if this RemoteViews is defined from a XML layout value. + */ + private int mViewId = View.NO_ID; + /** Class cookies of the Parcel this instance was read from. */ private Map<Class, Object> mClassCookies; @@ -4799,6 +4806,9 @@ public class RemoteViews implements Parcelable, Filter { inflater = inflater.cloneInContext(inflationContext); inflater.setFilter(shouldUseStaticFilter() ? INFLATER_FILTER : this); View v = inflater.inflate(rv.getLayoutId(), parent, false); + if (mViewId != View.NO_ID) { + v.setId(mViewId); + } v.setTagInternal(R.id.widget_frame, rv.getLayoutId()); return v; } @@ -5746,4 +5756,25 @@ public class RemoteViews implements Parcelable, Filter { } return true; } + + /** + * Set the ID of the top-level view of the XML layout. + * + * Set to {@link View#NO_ID} to reset and simply keep the id defined in the XML layout. + * + * @throws UnsupportedOperationException if the method is called on a RemoteViews defined in + * term of other RemoteViews (e.g. {@link #RemoteViews(RemoteViews, RemoteViews)}). + */ + public void setViewId(@IdRes int viewId) { + if (hasMultipleLayouts()) { + throw new UnsupportedOperationException( + "The viewId can only be set on RemoteViews defined from a XML layout."); + } + mViewId = viewId; + } + + /** Get the ID of the top-level view of the XML layout, as set by {@link #setViewId}. */ + public @IdRes int getViewId() { + return mViewId; + } } |
