2011-12-02 70 views
0

這是我的main.xml的RelativeLayout和切換按鈕

<RelativeLayout android:id="@+id/gloabal_permission" 
         android:layout_height="fill_parent" android:layout_width="wrap_content" 
         android:background="@drawable/settings_selector_down" 
         android:paddingTop="3dp" android:paddingBottom="3dp" 
         android:paddingRight="12dp" android:paddingLeft="15dp"> 
         <TextView android:id="@+id/TextView06" 
          android:layout_height="wrap_content" android:layout_width="wrap_content" 
          android:text="Gloabal permission" android:layout_marginTop="10dp"> 
         </TextView> 
         <ToggleButton android:id="@+id/globalpermissionbutton" 
          android:layout_width="wrap_content" android:layout_height="wrap_content" 
          android:text="ToggleButton" android:layout_alignParentRight="true"> 
         </ToggleButton> 
    </RelativeLayout> 

我應該怎麼做,當我點擊切換按鈕的RelativeLayout是打開(點擊一次切換按鈕已關閉)。我只是用togglebutton的監聽器綁定relativelayoutlistener。

+0

您是說當您點擊它時,此切換按鈕未設置爲打開或關閉狀態? – Cata

+0

我只想看任何例子如何做到這一點。 – fish40

+0

但你的例子不起作用? – Cata

回答

1

你必須爲你的相對佈局創建一個onClick()偵聽器。例如,

yourRelLayout.setOnClickListener(new OnClickListener({ 
    yourToggleButton.setChecked(true); 
})); 

,這是所有:)

祝你好運!