Skip to content

Instantly share code, notes, and snippets.

@kittinan
Created March 21, 2015 19:12
Show Gist options
  • Save kittinan/4273fe59ab9ab235699d to your computer and use it in GitHub Desktop.
Save kittinan/4273fe59ab9ab235699d to your computer and use it in GitHub Desktop.
Android Widget Recursive Clear Form
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.ScrollView;
/**
* Created by null on 3/22/15.
*/
public class WidgetUtil {
public static void clearForm(ViewGroup vg) {
int child_count = vg.getChildCount();
for (int i = 0; i < child_count; i++) {
View v = vg.getChildAt(i);
if (v instanceof ScrollView) {
((ScrollView) v).smoothScrollTo(0, 0);
} else if (v instanceof EditText) {
((EditText) v).setText("");
} else if (v instanceof RadioGroup) {
((RadioGroup) v).clearCheck();
} else if (v instanceof CheckBox) {
((CheckBox) v).setChecked(false);
}
if (v instanceof ViewGroup) {
//Viewgroup Recursive find
WidgetUtil.clearForm((ViewGroup) v);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment