Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Why don't you display a dialog with the two options before loading your new Activity? And then, according the user's selection display the corresponding xml?</p> <p>I would do it this way:</p> <ol> <li>You have your mainActivity running</li> <li>When the user clicks your button, you show an AlertDialog with the "positive" button representing the first xml file and the "negative" button representing your second xml.</li> <li>Upon click on any of the buttons, you show your second Activity by using different Intent-actions and checking which intent was used in the <code>onCreate</code> method of your second Activity.</li> </ol> <p>For your button:</p> <pre><code>Button button = (Button) findViewById(R.id.button); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent act2 = null; switch (which) { case DialogInterface.BUTTON_POSITIVE: // layout 1 act2 = new Intent("package.example.act2_layout1"); startActivity(act2); break; case DialogInterface.BUTTON_NEGATIVE: act2 = new Intent("package.example.act2_layout2"); startActivity(act2); } } }; AlertDialog.Builder builder = new AlertDialog.Builder(mainActivity.this); builder.setTitle("Make your choice") .setPositiveButton("Layout 1", listener) .setNegativeButton("Layout 2", listener); } }); </code></pre> <p>And then in the <code>onCreate</code> method:</p> <pre><code>Intent starter = getIntent(); if (starter.getAction().equals("package.example.act2_layout1")) { // use layout 1 } else if (starter.getAction().equals("package.example.act2_layout2")) { // use layout 2 } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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