0

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);
}

3 Answers3

1

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!
        }
    }               
}
Xaver Kapeller
  • 49,491
  • 11
  • 98
  • 86
  • Actully, i tried this but i wasn't succeed. The problem here is when i am in the registration page if i rotate the screen that calls to destroy after that oncreate. so The activity starting again. – Solution2Tech Jun 24 '14 at 11:23
  • Yes, of course. The `Activity` is recreated when the configuration changes. That is completely normal. The solution in my answer is specifically to solve that problem. You can add all the information you want to save to the `Bundle` in `onSaveInstanceState()` and read it again from the `Bundle` in `onCreate()`. What you add to the `Bundle` is saved regardless of how many times the `Activity` is recreated. – Xaver Kapeller Jun 24 '14 at 11:27
0

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.

Jithu
  • 1,478
  • 1
  • 13
  • 21
0
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.