Iterate the container layout view and process the views depending on which widget they are instances of. For example, if you want to hide everything Buttonand disable everything EditText:
for(int i=0; i < layout.getChildCount(); i++) {
View v = layout.childAt(i);
if (v instanceof Button) {
v.setVisibility(View.GONE);
}else
if (v instanceof EditText) {
((EditText)v).setEnabled(false);
}
}
Of course, if you want to add other properties, for example, to make it non-clickable or whatever, you would just add them to the correspondent, if from the previous code.
Then hide the keyboard :
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
A cleaner way to do this (if you know the identifiers of the views) is to store them in int[]and in a loop, instead of getting the view from the children from the layout, but as far as the result is, they are almost the same.
source
share