I have a problem. view.setVisibility(View.GONE) doesn't work for me anymore. I will show you what I'm working on.
I globally declared this outside of OnCreate() :
final ArrayList<View> ViewList = new ArrayList<View>();
int CurrentViewId = 0;
int EmployerViewId = 0;
int LastViewId = 0;
After that I added Views to it in OnCreate() like this:
ViewList.add(findViewById(R.id.content_main_lo));
ViewList.add(findViewById(R.id.data1_lo));
ViewList.add(findViewById(R.id.data2_lo));
... In total i got 6.
After the Next Button is clicked, the edittexts on each of these layouts should be checked for input. Checkinput returns true if all edittexts are filled in. So if it returns true, the Current View is taken from the Viewlist and made Invisible while the next view in the list will be made visible.
public void OnNextButtonClick(View v) {
if (CheckInput(v)) {
ViewList.get(CurrentViewId).setVisibility(View.GONE);
// ^^This
if (v.getId() == R.id.employer_btn)
CurrentViewId = EmployerViewId;
else {
CurrentViewId++;
if (CurrentViewId == EmployerViewId)
CurrentViewId = LastViewId;
}
ViewList.get(CurrentViewId).setVisibility(View.VISIBLE);
}
}
Now the result is, even if I filled in all edittexts correctly, and CheckInput actually returns true, the Current View (which is Index 1 in the ViewList, Index 0 works) doesnt get invisible. I debugged my program and had a closer look and everything goes as planned, and as it passes the ViewList.get(CurrentViewId).setVisibility(View.GONE); everything keeps working, but the view doesnt disappear on my phone. Then i can click the "Next" Button 4 more times, and the app crashes, because OnNextButtonClick works fine and seems to actually load the other Views somehow, but at the 5th time the app crashes because of an IndexOutOfBoundException, since there are only 6 Views in my ViewList and I have clicked the Button before.
Does anybody have an idea the the view just won't disappearing? The Method OnNextButtonClick works just fine for the previous View (Index 0)
Thanks a lot!
Here is Checkinput if needed: I'm basically just find fitting layouts for the pressed NextButton and i give the fitting layout to Border and return its boolean value
public boolean CheckInput(View v) {
LinearLayout layout = null;
if (v.getId() == R.id.employee_btn_1){
setContentView(R.layout.employee_data1);
layout = (LinearLayout) findViewById(R.id.employee_lay);
}
else if (v.getId() == R.id.employee_btn_2){
setContentView(R.layout.employee_data2);
layout = (LinearLayout) findViewById(R.id.employee_lay2);
}
// ...
return (Border(layout));
And here is the Border Method:
public boolean Border(LinearLayout layout) {
boolean errorfree= true;
int check = 0;
if (layout.getChildCount() != 0) {
for (int i = 0; i < layout.getChildCount(); i++) {
View view = layout.getChildAt(i);
if (view instanceof EditText) {
String input = "";
EditText edt = (EditText) view;
if (view.getId() == this.workas_et.getId()) {
input = this.workas_et.getText().toString();
} else if (view.getId() == this.communicate_et.getId()) {
input = this.communicate_et.getText().toString();
}
// ...
if (input.isEmpty()) {
edt.setBackgroundResource(R.drawable.border);
check++;
} else {
edt.setText(input);
}
}
}
}
if (check != 0) {errorfree= false; }
return errorfree;
}
setVisibility(View.GONE);
followed by asetVisibility(View.VISIBLE);
. Are you sure the logic in between is working? â K Neeraj Lal