I am having a silly issue with onClickListeners modifying GUI elements. Below I have a radioGroup holding two buttons, an EditText and a Spinner. When the choose_old radio button is selected, I simply wanted to toggle enable/disable between the Spinner and EditText. The variables select_run and new_run_name are both instance variables and are
obtained from my XML files.
select_run = (Spinner)runDialoglayout.findViewById(R.id.run_choice_spinner);
new_run_name = (EditText)runDialoglayout.findViewById(R.id.new_run_name);
RadioButton choose_old = (RadioButton)runDialoglayout.findViewById(R.id.select_old);
RadioButton choose_new = (RadioButton)runDialoglayout.findViewById(R.id.select_new);
choose_old.setOnClickListener(new OnClickListener(){
public void onClick(View arg0) {
Log.e("ERROR","GOT CLICK");
select_run.setEnabled(true);
new_run_name.setEnabled(false);
}
});
The ‘GOT CLICK’ message prints but I do not get the desired changes.
Note:
- In trying solutions, I had wrapped the GUI changes in a handler.post with no effect.
- If I set to enabled outside the onClickListener, it successfully changes it.
I’ve no doubt this is something dumb but can’t seem to figure out why this is happening
Try putting this code in the listener.