Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Would like to give a work around for this problem.</p> <p>Problem : How to use the same activity as both dialog and full screen based.</p> <p>Solution : </p> <ol> <li>Define your activity in your AndroidManifest.xml with the theme <code>@android:style/Theme.Dialog</code><br></li> <li>In your respective <code>.Java</code> file, check for an <code>intent</code> extra that defines <code>dialog</code> mode. <br></li> <li>If it does not exist, set the <code>Theme</code> to <code>android.R.style.Theme</code>. This is the default <code>theme</code> which is applied if you do not define any theme.</li> </ol> <p>Code :</p> <pre><code>boolean fDialogMode = getIntent().hasExtra("dialog_mode"); if( ! fDialogMode ) { super.setTheme(android.R.style.Theme); } </code></pre> <p>Alternate Solution:</p> <p>A more complex solution is to use <code>AlertDialog</code> as below:</p> <ol> <li>Define a <code>ListAdapter</code> class extended from <code>ArrayAdapter</code>. </li> <li><p>return <code>1</code> in <code>getCount</code> function</p> <pre><code>@Override public int getCount() { return 1; } </code></pre></li> <li><p>In the <code>getView</code> function, <code>inflate</code> the <code>layout</code> of the <code>activity</code> you need and do any customization before returning the <code>view</code>.</p> <pre><code>@Override public View getView( int position, View view, ViewGroup group ) { View v = view; if( v == null ) { v = getSystemService(Context.LAYOUT_INFLATER_SERVICE).inflate( &lt;layout res id&gt;, null ); } ... Do any customization here .... return v; } </code></pre></li> </ol> <p>This is definitely a second choice option by if you are not doing too much processing in the <code>activity</code> <code>class</code> this could be an option.</p> <p>Only reason to consider this solution could be that the logic to show it in a <code>dialog</code> is isolated to the places where it is used as a dialog.</p> <p>Both the options worked for me but for obvious reasons I am taking the first option. :-)</p>
 

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