2013-04-04 65 views
0

我創建一個佈局與RadioGroup中cotaining兩個按鈕。然後我得到一個可繪製的選擇器。performClick()不激活選擇

我應用了與android:backgroundandroid:button選擇器刪除小圓圈。

在onCreate方法我經由button.performClick()按下一個按鍵但按鈕的佈局不改變。即使我打電話button.setChecked(true)它不會改變。 實際上,它在第一次創建片段時起作用。但是,如果我按下第二個按鈕,加載另一個片段並返回後退按鈕,第二個按鈕仍然按下。

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
     Bundle savedInstanceState) { 
    final View f = inflater.inflate(R.layout.fragment_season, container, 
      false); 

    final RadioButton bt = (RadioButton) f.findViewById(R.id.bu_season_tabelle); 
    final RadioButton bs = (RadioButton) f.findViewById(R.id.bu_season_spielplan); 

    bt.setOnClickListener(new OnClickListener() { 

     public void onClick(View v) { 
      setTabelle(f); 
      v.setClickable(false); 
      bs.setClickable(true); 
     } 
    }); 

    bs.setOnClickListener(new OnClickListener() { 

     public void onClick(View v) { 
      setSpielplan(f); 
      v.setClickable(false); 
      bt.setClickable(true); 
     } 
    }); 

    bt.performClick(); 

    return f; 
} 

如果有人能幫助我,那會很好。

+0

把你的代碼

.... – 2013-04-04 10:20:59

回答

0

我找到了解決辦法:不要在onCreateView()調用button.performClick()我必須調用它onStart()