Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A different approach:</p> <p>Use <code>Fragments</code>. Fragments are added to containers and are replaced by others when you like. The replaced Fragment can be added to the stack, or not. That you can decide for yourself. In this case the flow would be like:</p> <ul> <li>MainActivity adds a Fragment A to a container.</li> <li>Button is pressed </li> <li>Fragment A is replaced by Fragment B. Fragment A is being added to<br> the stack with <code>.addToBackStack(..)</code></li> <li>Fragment B is shown</li> <li>Button is pressed</li> <li>Fragment B is replaced by Fragment C. Fragment B is not being added to the stack.</li> <li>Fragment C is shown</li> <li>Back is pressed</li> <li>Fragment A is shown</li> </ul> <p><strong>Update</strong></p> <p>You can start by reading the <a href="http://developer.android.com/guide/components/fragments.html" rel="nofollow">documention</a> Android provided. </p> <p>A simple example to get you started and explain the basics. I am using the Android support library v4 for fragment to support older versions than HoneyComb:</p> <p><strong>main_activiy - XML</strong></p> <pre><code>&lt;LinearLayout&gt; &lt;FrameLayout id:content_container/&gt; &lt;LinearLayout&gt; </code></pre> <p><strong>MainActivity</strong></p> <pre><code>public class MainActivity extends FragmentActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_activiy ); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.add(R.id.content_container, new FragmentA()); transaction.commit(); } } </code></pre> <p><strong>Fragment A</strong> (analog you can create Fragment B and C)</p> <pre><code>public class Fragment A extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragmentA, container, false); return view; } } </code></pre> <p>You can implement logic inside your <code>Fragment</code> and catch for example a click-event. This is how you can switch between fragments from a OnClickListener:</p> <pre><code>private class mClickListener implements OnClickListener { public void onClick(View v) { FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.content_container, new FragmentB); transaction.addToBackStack(...); // Remove this when you don't want it to be stacked transaction.commit(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload