2013-07-24 45 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