I am trying to develop an MySQL client, and there are is more screens with different dynamic content and I am looking for some simple way, how to not reload an activity on orientation, which always means executing a query form onCreate()
, which is not good.
For example:
Screen 1:
<RelativeLayout>
<STATIC-XML TextView></STATIC-XML TextView>
<STATIC-XML EditText></STATIC-XML EditText>
<STATIC-XML TextView></STATIC-XML TextView>
<STATIC-XML EditText></STATIC-XML EditText>
</RelativeLayout>
Screen 2:
<RelativeLayout>
<ListView>
<DYNAMIC-PROG ListViewItem>
<DYNAMIC-PROG TextView></DYNAMIC-PROG TextView>
</DYNAMIC-PROG ListViewItem>
<DYNAMIC-PROG ListViewItem>
<DYNAMIC-PROG TextView></DYNAMIC-PROG TextView>
</DYNAMIC-PROG ListViewItem>
</ListView>
</RelativeLayout>
Screen 3 (now the fun begins):
<RelativeLayout>
<ScrollView>
<HorizontalScrollView>
<TableLayout>
<DYNAMIC-PROG TableRow>
<DYNAMIC-PROG TextView></DYNAMIC-PROG TextView>
<DYNAMIC-PROG TextView></DYNAMIC-PROG TextView>
<DYNAMIC-PROG TextView></DYNAMIC-PROG TextView>
</DYNAMIC-PROG /TableRow>
<DYNAMIC-PROG TableRow>
<DYNAMIC-PROG TextView></DYNAMIC-PROG TextView>
<DYNAMIC-PROG TextView></DYNAMIC-PROG TextView>
<DYNAMIC-PROG TextView></DYNAMIC-PROG TextView>
</DYNAMIC-PROG /TableRow>
</TableLayout>
</HorizontalScrollView>
</ScrollView>
</RelativeLayout>
Here in Screen 3, in every TableRow
, will be the same count of TextViews,
but on every start of this screen, there will be a different number of TextViews
(every TextView
for every column of current table form MySQL DB I am loading)
And finally Screen 4
<RelativeLayout>
<ScrollView>
<TableLayout>
<DYNAMIC-PROG TableRow>
<DYNAMIC-PROG TextView></DYNAMIC-PROG TextView>
<DYNAMIC-PROG EditText></DYNAMIC-PROG EditText>
</DYNAMIC-PROG /TableRow>
<DYNAMIC-PROG TableRow>
<DYNAMIC-PROG TextView></DYNAMIC-PROG TextView>
<DYNAMIC-PROG EditText></DYNAMIC-PROG EditText>
</DYNAMIC-PROG /TableRow>
</TableLayout>
</ScrollView>
</RelativeLayout>
And here it is. The content is loaded via AsyncTask
, whole logic, storing to arrays etc. Is in doInBackground()
and then I am drawing it to layout in onPostExecute()
, including @Override setOnClickListener
, and so on.
Now, on orientation change, it will recreate the activity and again loading all data (calling AsyncTask
)
I need to somehow store the dynamically created things, just to redraw them, not recreating them.
I need to store their content and their ID, if exists (if I have called object.setId(id);
I got through some guides, like
Restoring state of TextView after screen rotation?
Good solution to retain listview items when user rotate phone and keep all data in ArrayAdapter
...
And nothing worked for me.
Best thing I have achieved was just recreating the activity. But these guides more often just did not how any of existing content on orientation change.
So, Is there any united solution, for any existing layout?