Compartir a través de


View.AutofillId Property

Definition

Gets the unique, logical identifier of this view in the activity, for autofill purposes. -or- Sets the unique, logical identifier of this view in the activity, for autofill purposes.

public Android.Views.Autofill.AutofillId? AutofillId { [Android.Runtime.Register("getAutofillId", "()Landroid/view/autofill/AutofillId;", "", ApiSince=26)] get; [Android.Runtime.Register("setAutofillId", "(Landroid/view/autofill/AutofillId;)V", "GetSetAutofillId_Landroid_view_autofill_AutofillId_Handler", ApiSince=28)] set; }
[<get: Android.Runtime.Register("getAutofillId", "()Landroid/view/autofill/AutofillId;", "", ApiSince=26)>]
[<set: Android.Runtime.Register("setAutofillId", "(Landroid/view/autofill/AutofillId;)V", "GetSetAutofillId_Landroid_view_autofill_AutofillId_Handler", ApiSince=28)>]
member this.AutofillId : Android.Views.Autofill.AutofillId with get, set

Property Value

The View's autofill id.

Attributes

Remarks

Property getter documentation:

Gets the unique, logical identifier of this view in the activity, for autofill purposes.

The autofill id is created on demand, unless it is explicitly set by #setAutofillId(AutofillId).

See #setAutofillId(AutofillId) for more info.

Java documentation for android.view.View.getAutofillId().

Property setter documentation:

Sets the unique, logical identifier of this view in the activity, for autofill purposes.

The autofill id is created on demand, and this method should only be called when a view is reused after #dispatchProvideAutofillStructure(ViewStructure, int) is called, as that method creates a snapshot of the view that is passed along to the autofill service.

This method is typically used when view subtrees are recycled to represent different content* &mdash;in this case, the autofill id can be saved before the view content is swapped out, and restored later when it's swapped back in. For example:

EditText reusableView = ...;
            ViewGroup parentView = ...;
            AutofillManager afm = ...;

            // Swap out the view and change its contents
            AutofillId oldId = reusableView.getAutofillId();
            CharSequence oldText = reusableView.getText();
            parentView.removeView(reusableView);
            AutofillId newId = afm.getNextAutofillId();
            reusableView.setText("New I am");
            reusableView.setAutofillId(newId);
            parentView.addView(reusableView);

            // Later, swap the old content back in
            parentView.removeView(reusableView);
            reusableView.setAutofillId(oldId);
            reusableView.setText(oldText);
            parentView.addView(reusableView);

NOTE: If this view is a descendant of an android.widget.AdapterView, the system may reset its autofill id when this view is recycled. If the autofill ids need to be stable, they should be set again in android.widget.Adapter#getView(int, android.view.View, android.view.ViewGroup).

Java documentation for android.view.View.setAutofillId(android.view.autofill.AutofillId).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to