0

I am trying to create a custom edittext that shows a progress icon (like typing....) while the user is typing

my layout is like this:

<RelativeLayout android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <android.support.design.widget.TextInputLayout 
        android:id="@+id/search_parent"
        android:visibility="invisible"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <core.controls.DelayedAutoCompleteTextView android:id="@+id/search"
            android:layout_width="match_parent"
            android:gravity="start"
            android:maxLines="1"
            android:lines="1"
            android:singleLine="true"
            android:textColor="#000"
            android:layout_height="match_parent"
            android:imeOptions="actionSearch"
            android:textAppearance="?android:attr/textAppearanceMedium" 
            app:delay="1000"
            app:progress="@+id/progress"/>
    </android.support.design.widget.TextInputLayout>
    <ProgressBar
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:visibility="gone"
        android:layout_alignParentEnd="true"
        android:id="@+id/progress"/>
</RelativeLayout>

I have also declared this styleable in the values folder

<declare-styleable name="dact">
    <attr name="delay"
        format="integer" />
    <attr name="progress"
        format="reference" />
</declare-styleable>

and in the view's constructor I have successfully retrieved the progress bar's id using :

 int progress_id = a.getResourceId(Resource.Styleable.dact_progress, 0);

my question is , how can I get a reference to the actual progressbar since it is not even in the same viewgroup as the edittext?

thanks in advance for any help you can provide

Cruces
  • 3,029
  • 1
  • 26
  • 55

1 Answers1

1

In View#onAttachedToWindow, when your view gets attached to its parent, you can traverse view hierarchy triying to find the closest required view with given ID, e. g.

ViewGroup parent = (ViewGroup) getParent();
View target;
while ((target = parent.findViewById(id)) == null) {
    parent = (ViewGroup) parent.getParent();
}

If there's no such view, this code will lead to an exception.

Miha_x64
  • 5,973
  • 1
  • 41
  • 63