There are two different xml files in layout and layout-land for the respective modes. As I want to set the values back in the edittexts even when orientation changed, I am using android:configChanges="orientation|keyboardHidden"
in manifest file. This deactivates the execution of onCreate() method again and the present activity is not destroyed.
I have two frames in my app. First frame contains 25 edittexts and second contains 10 buttons. So in portrait mode, these frames are one after the other and in landscape mode one next to the other. To get this view according to modes, I wrote setContentView(R.layout.main);
in the onConfigurationChanged()
method. But my problem here is I am able to store the values that entered already in the editTexts in onConfigurationChanged()
. But I am unable to set the values back to the edittexts after setting to the respective layout. Because I am getting respective layout, but with empty edittexts. The following code snippet gives overview of my problem.
public void onCreate()
{
setContentView(R.layout.main);
gridView = (GridView) findViewById(R.id.gridView1);
gridView.setAdapter(new EditTextAdapter(this)); //This creates 25 edittexts in the gridview which is in first frame.
}
public void getEditTexts()//getting the edittext objects here in the activity class
{
editText1=gridView.getChildAt(k);
...........
...........
}
public void onConfigurationChanged()
{
String s1=editText1.getText().toString();//Here I am using technique to store the values.
setContentView(R.layout.main);
gridView.setAdapter(new EditTextAdapter(this));
getEditTexts();
editText1.setText(s1); //here is my problem. I am unable to set values back in the editText.
}
Where I am going wrong? How to set the values back like this in 25 edittexts in the present mode if they are set in previous mode. Please suggest. Here I guess the values are set in the old edittext objects itself even though the mode is changed. How to set the values in the new edittext objects? How come the values are set in old edittext objects if they are not present in the current layout? Or there is another reason for this problem?