title: OnCheckedChanged not working in Fragment Android
body: <p>Hi in fragment an getting the value of checkbox using <strong>OnCheckedChanged</strong> but its not working, like not ven calling the method when I check the CheckBox. Below is the code how its imlemented.</p>
  
  <p>The XML file of how CheckBox is used.</p>
  
  <pre><code>     &lt;CheckBox
        android:id="@+id/cbDefault"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".2" /&gt;
  </code></pre>
  
  <p>The Java code for fragment is below </p>
  
  <pre><code>import android.widget.CompoundButton.OnCheckedChangeListener;
  
  public class ProfileFrag extends AbsFragment implements OnCheckedChangeListener {
  
  private EditText defaultIdText;
  private EditText customText;
  private EditText randomText;
  private TextView phoneText;
  private Button setButton;
  protected ProfileUpdate profUpdate;
  protected String sDefaultId;
  protected String sCustomId;
  protected String sRandomId;
  protected String sPhoneId;
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      View profView = inflater.inflate(R.layout.intermediate_screen,
              container, false);
  
      defaultIdText = (EditText) profView.findViewById(R.id.etDefault);
      customText = (EditText) profView.findViewById(R.id.etCustom);
      randomText = (EditText) profView.findViewById(R.id.etUname);
      phoneText = (EditText) profView.findViewById(R.id.etPhoneNumber);
  
      return profView;
  }
  
  @Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      super.onViewCreated(view, savedInstanceState);
  
      mSharedData = new SharedData(getActivity());
      //
      // phoneNumber = DeviceIdGen.DevicePhoneNum(getActivity());
  
      phoneText.setText(mSharedData.getPhNum());
      randomText.setText(mSharedData.getRandomId());
      customText.setText(mSharedData.getCustomId());
      defaultIdText.setText(mSharedData.getDefaultId());
  
  
  @Override
  public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
      // TODO Auto-generated method stub
      switch (buttonView.getId()) {
  
      case R.id.cbDefault:
          sDefaultId = defaultIdText.getText().toString();
          mSharedData.setUniqueid(sDefaultId);
          mSharedData.commit();
  
          break;
  
      case R.id.cbCustom:
          sCustomId = customText.getText().toString();
          mSharedData.setUniqueid(sCustomId);
          mSharedData.commit();
          break;
  
      case R.id.cbRandom:
  
          mSharedData.setUniqueid(sRandomId);
          mSharedData.commit();
          default:
          break;
      }
  }
  </code></pre>
  
  <p>}</p>