I need help, my layouts and containers are lingering on after I have used the code bellow to remove them.
For example I have page 1 that adds a small text that explains how to use the part of the program under scrutiny, and then the next page allows the user to add a name where there is a label with text Name: and a EditText to add the name in next to it.
Both the components ‘stick’ but the EditText is reproduced multiple times and I have no idea why! I would also like to stop the sticking.
By sticking I simply mean that the view does not leave view like it should(still visible).
Here is some code.
if(pageCount == lastPageCount--)
{
page2Layout.removeAllViews();
//page2Layout.setVisibility(View.GONE);
//Reset all text views.
helpText.setText("");
}
helpText.setLayoutParams(params);
helpText.setText("You cannot view this part sorry :S\n\n" +
"You cannot view this part sorry :S.\n" +
"You cannot view this part sorry :S");
page1Layout.addView(helpText);
page1Layout.setVisibility(View.VISIBLE);
}
else if(pageNumber == 2)
{
if(pageCount == lastPageCount++)
{
//page1Layout.setVisibility(View.GONE);
page1Layout.removeAllViews();
}
else if (pageCount == lastPageCount++)
{
page3Layout.setVisibility(View.GONE);
}
//Name Position + Containers etc
LinearLayout nameLayout = new LinearLayout(this);
nameLayout.setOrientation(LinearLayout.HORIZONTAL);
nameLayout.setLayoutParams(params);
TextView nameLabel = new TextView(this);
nameLabel.setLayoutParams(params);
nameLabel.setText("Name: ");
EditText nameTextField = new EditText(this);
nameTextField.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
//All to name layout.
nameLayout.addView(nameLabel);
nameLayout.addView(nameTextField);
page2Layout.addView(nameLayout);
page2Layout.setVisibility(View.VISIBLE);
}
Beware of the stupid mistakes coders can make when they stare at code too long.
For anyone who is also stuck similarly, lastPageCount++ will increment lastPageCount after the statement has run.
Therefore the wrong code is run.