Help Needed : Tabs created in Dialogs now disappear if not displayed from same context they were created

59 views
Skip to first unread message

namg...@gmail.com

unread,
May 2, 2021, 10:05:13 AM5/2/21
to DroidScript
Hello,
I noticed that between DS 1.8 and 2.06, Tabs don't display in Dialogs created in advance.
See the code below : tabs are always visible in 1.8, they are only displayed when called from OnStart() in 2.06. 
Is it a bug or a feature ? How can I reorganize my code ? I need to display the Dialogs many times, so it must be of "create once, use many" type. Hence my "object oriented" approach.
Thanks by advance !
Regards, 
Paul

=
cfg.Holo;

//Called when application is started.
function OnStart()
{  
    //Initialize the Dialog Object
    OBJECTDLG.Initialize();
    
//Create a layout with objects vertically centered.
lay = app.CreateLayout( "linear", "VCenter,FillXY" );

//Create a button 1/3 of screen width and 1/10 screen height.
btn = app.CreateButton( "Press Me", 0.3, 0.1 );
btn.SetMargins( 0, 0.05, 0, 0 );
lay.AddChild( btn );
//Set function to call when button pressed.
btn.SetOnTouch( I( btn_OnTouch ));
//Add layout to app.
app.AddLayout( lay );
// Tabs do show off when Dialog is called from here
    // OBJECTDLG.ShowDlg();
}


//Called when user touches our button.
function btn_OnTouch()
{
//Call to Show function of Object Dialog
    // Tabs do NOT show off when Dialog is called from here
OBJECTDLG.ShowDlg();
// neither does this work : 
    // dlg.Show();
    
 
}


var OBJECTDLG = {
        Initialize: function () {
       
    dlg = app.CreateDialog( "This is a Tabbed Dialog" );
        this.Objectdlg = dlg;
        layDlg = app.CreateLayout( "linear", "VCenter,FillXY" );
        layDlg.SetSize( 0.7, -1 );
        dlg.AddLayout( layDlg );
        
        tabs = app.CreateTabs( "Controls,Groups,Screens", -1, -1, "VCenter" );
        layDlg.AddChild (tabs);
        
               
        },
        
       
        ShowDlg: function () {
        
        
        this.Objectdlg.Show();
        
        // neither does this work : 
        // dlg.Show();
    }
    
};



Steve Garman

unread,
May 2, 2021, 12:36:15 PM5/2/21
to DroidScript
I would try something like this, only because I can't make anything else work

cfg.Holo;

//Called when application is started.
function OnStart()
{
    
   //Create a layout with objects vertically centered.
   lay = app.CreateLayout("linear", "Center,FillXY");

   //Create a button 1/3 of screen width and 1/10 screen height.
   btn = app.CreateButton("Show", 0.3, 0.1);
   btn.SetMargins(0, 0.05, 0, 0);
   lay.AddChild(btn);
   
   btn2 = app.CreateButton("Hide", 0.3, 0.1);
   btn2.SetMargins(0, 0.05, 0, 0);
   lay.AddChild(btn2);
   

   //Set function to call when button pressed.
   btn.SetOnTouch(I(btn_OnTouch));
   btn2.SetOnTouch(I(btn2_OnTouch));

   //Add layout to app.
   app.AddLayout(lay);

}

//Called when user touches our button.
function btn_OnTouch()
{
   if(typeof OBJ!="function")
     OBJ = new OBJECTDLG
   OBJ.Show();
}
function btn2_OnTouch()
{
   if(typeof OBJ!="function")
      return
   OBJ.Hide();
}

OBJECTDLG = function()
{
      var dlg = app.CreateDialog("This is a Tabbed Dialog");
      this.Show=dlg.Show;
      this.Hide=dlg.Hide;
      var layDlg = app.CreateLayout("linear", "VCenter,FillXY");
      dlg.AddLayout(layDlg);

      var tabs = app.CreateTabs("Controls,Groups,Screens", -1, -1,
         "VCenter");
      layDlg.AddChild(tabs);
      layDlg.SetSize(0.7, -1);
      var iDlg=dlg
  } ////
  

Message has been deleted

Steve Garman

unread,
May 2, 2021, 1:03:48 PM5/2/21
to DroidScript
Please ignore the last line 
   var iDlg=dlg

It was part of an Initialize function I was trying to add

If you ever display the dialog without the tabs it seems to be impossible to get them back
You just have to make sure you only hide the whole dialog

I also have to stop replying from my phone because I have to shift into desktop mode I can't see the typos

namg...@gmail.com

unread,
May 2, 2021, 5:56:48 PM5/2/21
to DroidScript
Many thanks, Steve, for the quick and clever reply.
With the help of your code I even found a simple workaround to avoid restructuring of my code.
I simply defered OBJECTDLG.Initialize() until juste before OBJECTDLG.ShowDlg() was about to be invoked for the first time.
And prevented further Initializing with a flag.
Regards,
Paul


//Called when user touches our button.
function btn_OnTouch()
{ if( !isinit) OBJECTDLG.Initialize();
        isinit=true;
//Call to Show function of Object Dialog
    // Tabs do now show off when Dialog is called from here
  OBJECTDLG.ShowDlg();
 

Reply all
Reply to author
Forward
0 new messages