Why do the text of EditText, Button etc reset when the view is hidden by another layout? How can I make them retain the text?
<p>Basically </p>

<ul>
<li>I have two layouts activity_main_layout.xml as well as layout2.xml</li>
<li>I have created two tabs on the ActionBar using the <strong>getActionbar().newTab()</strong> method</li>
<li>I have a <strong>Button</strong> and a text box (<strong>EditText</strong>) in <strong>activity_main_layout.xml</strong> (first tab)</li>
<li><p>Both the button and the text box have a <strong>dynamically</strong> entered text: "Test 123"</p></li>
<li><p>When Tab 2 is selected, I have a statement of code that says: <strong>setContentView(R.layout.layout2)</strong> so that it shows the second layout and similarly for Tab 1: <strong>setContentView(R.layout.activity_main)</strong></p>

<p>When Tab 1 is reselected, the dynamically entered text "Test 123" is gone and I am left with the text that was set in design time in the XML. So I am currently forced the save the contents of the Buttons and EditTexts before a tab is selected and restore them after it was selected. </p></li>
</ul>

<p>I don't think this is the right way to do it. I am already utilizing <strong>onSaveInstanceState()</strong> and <strong>onRestoreInstanceState()</strong> with <strong>savedInstanceState.putXX and getXX</strong> etc to save the contents when the screen rotates but it doesn't seem to work with the current issue. I have been unable to find an answer so far. Does anyone have any clues please? Any responses will be appreciated.</p>
