Android traversal controls
Overview
When we log in or register to submit what data we need to fill in our personal information, so we need to determine that our fields have been entered.
How to traverse controls in our interface
According to international practice, let's take a look at the source code:
package .study_01_08; import ; import ; import ; import ; import ; import ; public class Android_2Activity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { (savedInstanceState); setContentView(.activity_android_2); findViewById(.btn_send).setOnClickListener(new () { @Override public void onClick(View v) { ConstraintLayout root = findViewById(.android_root); for (int i = 0; i < (); i++) { View view = (i); if (view instanceof EditText && ((EditText) view).getText().length() == 0) { (Android_2Activity.this, "Sorry Please fill in all the information", Toast.LENGTH_SHORT).show(); return; } } } }); } }
These codes are all the code that implements our traversal of the controls in the interface.
Then let's explain:
Let's first determine a large main layout.
Then get his child control. And through our use of his Count to get it.
Use the instanceof keyword to determine whether it is the control you want.
Finally, by judging whether his text length is 0, you can determine whether all fields have been entered.
Supplementary knowledge:Android—Judge current time period
Idea: Get the current time relative to the number of minutes of the day, and then compare it with the time (converted into minutes) after the time period in chronological order (such as 8:00-9:00, compared with 9:00).
Part of the code:
Current time
Calendar calendar = (); int hour = (Calendar.HOUR_OF_DAY); int minute = (); int CurrentTimeTotalMinute = hour * 60 + minute;
Time period: String time="8:00-9:00"
String[] two = ("-"); String[] second = two[1].split(":"); int secondTotalMinute = (second[0]) * 60 + (second[1]);
The above example of Android determining whether all fields have been entered is all the content shared by the editor. I hope it can give you a reference and I hope you can support me more.