I'm new to android programming and I think my biggest problem is that I can't really wrap my mind around all this inflating stuff. Can you help me with this one?
I'm working on a form, the forms content is seperated into different pages. Before you can proceed to the next page of the form, you need to fill in all obligatory EditTexts. So when the "next" button is clicked, i want to have my form edittexts checked for empty input. If there are Edittexts left empty, a border is drawn around them and you can't proceed.
My Problem is, that even if I fill in some Edittexts, they are still always perceived as empty. So i fill them in, click the "next" button, and a border is drawn around each one, regardless of being empty or not.
basically this is the Method causing the problem:
public void Border(View view){
if (view instanceof EditText) {
EditText edt = (EditText) view;
if (edt.getText().toString().trim().length() == 0) {
edt.setBackgroundResource(R.drawable.border);
}
}
}
So I want to check if (if the given view is an EditText) the EditText is empty. If yes, i want to draw a border around it. Obviously if (edt.getText().toString().trim().length() == 0) is always true. The Method Border() is called from here:
public boolean CheckInput(View v) {
EditText phone = (EditText) findViewById(R.id.phonenr_et);
EditText email = (EditText) findViewById(R.id.email_et);
CheckBox box = (CheckBox) findViewById(R.id.agreement_checkbox);
if (v.getId() != R.id.job_hunting_btn) {
LinearLayout layout = (LinearLayout) findViewById(R.id.job_hunt_lay);
if (layout.getChildCount() != 0) {
for (int i = 0; i < layout.getChildCount(); i++) {
View view = layout.getChildAt(i);
Border(view); // <-- Border is called
}
}
}
...
}
In CheckInput() I'm looping through a views Children and put put them into my Border Method. CheckInput() is called here:
public void OnNextButtonClick(View v) {
if (CheckInput(v)) {
ViewList.get(CurrentViewId).setVisibility(View.GONE);
if (v.getId() == R.id.job_hiring_btn)
CurrentViewId = ArbeitgeberViewId;
else {
CurrentViewId++;
if (CurrentViewId == ArbeitgeberViewId)
CurrentViewId = LastViewId;
}
ViewList.get(CurrentViewId).setVisibility(View.VISIBLE);
}
}
Here I want to make sure that you first have your Input checked before you can proceed to the next part of your form.
Here is my OnCreate() Method:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setContentView(R.layout.content_main);
setContentView(R.layout.job_hiring_data1);
setContentView(R.layout.job_hiring_data2);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
ViewList.add(findViewById(R.id.content_main_lo));
ViewList.add(findViewById(R.id.job_hiring_data1_lo));
ViewList.add(findViewById(R.id.job_hiring_data2_lo));
ViewList.add(findViewById(R.id.job_hunt_lay));
ArbeitgeberViewId = ViewList.size();
ViewList.add(findViewById(R.id.offered_job_data1_lo));
LastViewId = ViewList.size();
ViewList.add(findViewById(R.id.formular_finished_lo));
ImprintViewId = ViewList.size();
ViewList.add(findViewById(R.id.imprint_lo));
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
Do I need to "inflate" the Edittext first or something? I'm honest, this is a group project, so everything seen in OnCreate() was created by a group member and i don't really know whats going on there -
I hope you can help me !
Thank you in advance!