Created
March 21, 2015 19:12
-
-
Save kittinan/4273fe59ab9ab235699d to your computer and use it in GitHub Desktop.
Android Widget Recursive Clear Form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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