I have a small timer app and EditText widgets named etH, etM and etS which allow input and show the time ticking. When the start button is clicked and the timer is started, I forbid the interaction by doing the following:
btnS.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (calculateMS() != 0) {
OnTimerStartButtonClicked();
initiateTimer();
DisableEditTexts();
...
The method:
public void DisableEditTexts() {
etH.setFocusable(false);
etM.setFocusable(false);
etS.setFocusable(false);
}
By pressing the reset button I want to re-enable the interaction by calling the method the does the reverse thing (sets focusable to true):
btnR.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
OnTimerResetButtonClicked();
clearValues();
EnableEditTexts();
...
The problem: the edittexts do NOT become focusable by clicking the reset button. All I’m doing in last method is
etH.setFocusable(true);
etM.setFocusable(true);
etS.setFocusable(true);
What am I doing wrong?
Try calling
EditText#setFocusableInTouchMode()instead:When you call
setFocusable(false), behind the scenes,setFocusableInTouchMode(false)is called for you. However when you callsetFocusable(true), nothing else happens behind the scenes, leavingsetFocusableInTouchMode()asfalse.When you call
setFocusableInTouchMode(true), a similar thing happens,setFocusable(true)is called for you. And the same as beforesetFocusableInTouchMode(false), does not callsetFocuable(false).Take a peak at the source code to see this quirk.