2016-02-06 21 views
-2

enter image description here如何設置在機器人的可見用於搜索條和TextView的

**有一個開關按鈕,搜索欄和文本鑑於上述圖像
所以這個活動開始時英寸我想查找欄和文本視圖默認 不可見,當我打開開關按鈕,搜索欄和文本視圖都應該可見 請爲此操作提供一個簡單的代碼。

我已經嘗試使用所有消失,可見和不可見的東西。但沒有顯示任何效果。

**

+3

把你的代碼..讓我們看看。 –

回答

0

你有沒有像下面那樣試過?

@Override 
    protected void onCreate(Bundle savedInstanceState){ 
    setContentView(R.layout.activity_main); 

    // find all view id here 

    textview.setVisiblity(View.GONE); 
    seekBar.setVisiblity(View.GONE); 

    mySwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 
     public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 
      // do something, the isChecked will be 
      // true if the switch is in the On position 
      if(isChecked){ 
       textview.setVisiblity(View.VISIBLE); 
       seekBar.setVisiblity(View.VISIBLE); 
      }else{ 
       textview.setVisiblity(View.GONE); 
       seekBar.setVisiblity(View.GONE); 
      } 
     } 
    }); 
    } 
+0

究竟是什麼複合按鈕? –

+0

CompoundButton.OnCheckedChangeListener是開關的開/關事件偵聽器。在這裏檢查更多細節http://stackoverflow.com/q/11278507/1168654 –

+0

當我寫這個..並運行它..活動不運行..它顯示不幸停止..當我刪除這部分的代碼..你給了..然後它運行..要做什麼? –

相關問題