2013-07-24 38 views
2

这里是我的xml文件我怎样才能从另一个视图查看

   <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> 

我想要得到的进度情况使用功能testGetView,而不是把它使用一个资源ID

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

} 

回答

1

你有设置一个ID为您的ProgressBar,然后从您的按钮,获得它的父视图与getParent(),将其转换为ViewGroup,然后拨打电话findViewById(int id)与您的ID为ProgressBar

+0

非常感谢,我使用getParent()强制转换为View并找到它,现在我可以在每一行中获得它 – david