Reputation: 29
My problem is i am unable to handle the portrait and landscap mode operations. In the screen i have one register form but that is in gone state. When i click register button that will come. So when i goes to landscape in that if i am rotate the screen what will come again in the gone in portrait. So please give some suggestions how can i handle that.
code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.equipmentmanagement);
context = this;
insertAnalasysMethodVlaues();
insertEquipmentTypeValues();
initUI();
showEquipmentTypeSpinner();
showAnalasisTypeSpinner();
equipmentTable = new EquipmentTable(context);
listequipment = equipmentTable.selectAllRecords();
showRecords(listequipment);
equipment_add.setOnClickListener(this);
equipment_search.setOnClickListener(this);
search.setOnClickListener(this);
insert.setOnClickListener(this);
cancel.setOnClickListener(this);
equipmentmanagement_text.setOnClickListener(this);
equipment_loadall.setOnClickListener(this);
equipment_type_spinner.setOnItemSelectedListener(this);
analysis_method_spinner.setOnItemSelectedListener(this);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
Upvotes: 0
Views: 78
Reputation: 29
boolean isSearch = false,isModification = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.equipmentmanagement);
initUI();
if(savedInstanceState != null)
{
boolean isSearch = savedInstanceState.getBoolean("search_visible");
boolean isModification = savedInstanceState.getBoolean("modification_visible");
if(isSearch)
{
searchEquipmentDetails();
}
else if(isModification)
{
showEquipmentModificationDetails();
}
else
{
loadall();
}
}
context = this;
insertAnalasysMethodVlaues();
insertEquipmentTypeValues();
showEquipmentTypeSpinner();
showAnalasisTypeSpinner();
equipmentTable = new EquipmentTable(context);
listequipment = equipmentTable.selectAllRecords();
showRecords(listequipment);
equipment_add.setOnClickListener(this);
equipment_search.setOnClickListener(this);
search.setOnClickListener(this);
insert.setOnClickListener(this);
cancel.setOnClickListener(this);
equipmentmanagement_text.setOnClickListener(this);
equipment_loadall.setOnClickListener(this);
equipment_type_spinner.setOnItemSelectedListener(this);
analysis_method_spinner.setOnItemSelectedListener(this);
}
this is the code for writing on create to compare state
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean("search_visible", isSearch);
outState.putBoolean("modification_visible", isModification);
}
You have to include the state of the project.
And make sure do the boolen modifications when click on the items.
private void searchEquipmentDetails()
{
isSearch = true;
isModification = false;
equipment_details.setVisibility(View.GONE);
equipment_modifications.setVisibility(View.GONE);
equipment_details_search.setVisibility(View.VISIBLE);
equipment_search_edittext.setText("");
}
private void showEquipmentModificationDetails()
{
isSearch = false;
isModification = true;
equipment_details.setVisibility(View.GONE);
equipment_modifications.setVisibility(View.VISIBLE);
equipment_details_search.setVisibility(View.GONE);
equipment_name_edittext.setText("");
equipment_id_edittext.setText("");
insert.setText("Insert");
b = true;
}
I think in this way we will handle the runtime application changes and saved the state.
Upvotes: 0
Reputation: 49817
What you have to do is save if the login is displayed to the user. One way you could do this is by overriding onSaveInstanceState()
and adding the information to the Bundle
:
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean("login_visible", isLoginVisible);
}
And then in onCreate you can get the value from the savedInstanceState
like this:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
if(savedInstanceState != null) {
boolean isLoginVisible = savedInstanceState.getBoolean("login_visible");
if(isLoginVisible) {
// Set the visibility of the login back to View.VISIBLE!
}
}
}
Upvotes: 1
Reputation: 1478
You can use some flag values integer/boolean
to keep the states of the form. and in protected void onCreate(Bundle savedInstanceState) {}
bind the view according to the state of the form. ie, you can show the the disabled/enabled button according to the state of the form.
Upvotes: 0