jeudi 16 février 2017

CheckBox setChecked has no effect

I've read all the answers to this question on here and nothing has helped yet.

public class ServerConfigFragment extends Fragment {

  private CheckBox checkBox_HDMI = null;
  private Handler updateScreen;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  updateScreen = new Handler();

  checkBox_HDMI = (CheckBox) rootView.findViewById(R.id.checkBox_Server_Conf_HDMI);

  checkBox_HDMI.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
        {
            m_commsController.sendCmd(VideoStreamSettings.sendHdmiCommand(isChecked));
        }
    });

  final boolean hdmi = getHdmiSettingFromServer();

  updateScreen.post(new Runnable() {
            @Override
            public void run() {  
              checkBox_HDMI.setSelected(hdmi);
            }
          });
  }
}

So upon my app's initial launch it querys the server's hdmi status and I want to set my checkbox to match that. I can see from the log I'm getting the correct value but so far I haven't been able to get my checkbox to check on/off programmatically. I've tried with and without a Handler, hardcoding true and false into setChecked(), and placing the code in onResume. Any ideas?




Aucun commentaire:

Enregistrer un commentaire