When attempting to save info to a server, I disable EditTexts (odds are the user can't change the info, but better safe than sorry).
In order to prevent the user from using the EditTexts, I can use either setEnabled(false)
or setFocusable(false)
. In order to start using the EditTexts again, I call setEnabled(true)
or setFocusable(true); setFocusableInTouchMode(true)
.
I'm guessing using setEnabled
is more efficient because there are less method calls, but is this the case (basically, I'd like to know which method is more efficient)?
Or are there other side-effects of using one vs the other that I don't know about?
Edit - Solution
In order to prevent myself from needing to setEnable(true/false)
to multiple different Views
in multiple different Fragments
, I implemented the following code (I took the idea from another StackOverflow answer):
public static void setViewAndChildrenEnabled(View view, boolean enabled) {
view.setEnabled(enabled);
if(view instanceof ViewGroup) {
ViewGroup viewGroup = (ViewGroup) view;
for(int i = 0; i < viewGroup.getChildCount(); i++) {
View child = viewGroup.getChildAt(i);
setViewAndChildrenEnabled(child, enabled);
}
}
}
I put this in my Utils
package so any Activity/Fragment
can call it. It works pretty nicely.