david
david

Reputation: 21

how can I get View from another view

here is my xml file

             <FrameLayout 
                 android:layout_alignParentRight="true"
                 android:layout_alignParentBottom="true"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 >
                 <Button
                    android:id="@+id/button1"
                    style="?android:attr/buttonStyleSmall"
                    android:layout_width="50dp"
                    android:layout_height="30dp"
                    android:text="@string/productButton_download"
                    android:onClick="testGetView"
                     />

                 <ProgressBar
                     style="?android:attr/progressBarStyleHorizontal"
                     android:layout_width="50dp"
                     android:layout_height="30dp"
                     android:visibility="invisible"
                      />
             </FrameLayout>

I want get the ProgressBar instance use the function testGetView instead of get it use a resource id

public void testGetView(View button) {
    // what can I do use this view to get the progressbar below it

}

Upvotes: 2

Views: 63

Answers (1)

VinceFR
VinceFR

Reputation: 2571

you have to set an id to your ProgressBar, then from your button, get its parent view with getParent(), cast it to ViewGroup and then call findViewById(int id) with the id of your ProgressBar

Upvotes: 1

Related Questions