customdialog2: buttons

christianK

Member
Licensed User
Longtime User
hi there,

i am a php progger and new to b4a - and even new to visual basic in general. please dont bash me for stupid questions
i try to learn by modifying codes from others.

my problem since yesterday (and i am sure, its a simple stupid easy *****!) is, that b4a seems not to notify my button-clicks in a customdialog2 - box from andrew graham´s great dialog-lib.

here ist the code from his original-example, found in libery-zip:

B4X:
Sub btnCustom2_Click
   Dim cd As CustomDialog2
   Dim pnl As Panel
   pnl.Initialize("pnl")
   Dim bgnd As ColorDrawable
   bgnd.Initialize(Colors.Cyan, 5dip)
   pnl.Background = bgnd
   Dim btn1 As Button
   btn1.Initialize("btn1")
   btn1.Text = "Press me"
   pnl.AddView(btn1, 80dip, 50dip, 60dip, 60dip)
   lbl1.Initialize("")
   pnl.AddView(lbl1, 50dip, 120dip, 120dip, 60dip)
   
   Dim lv As ListView
   lv.Initialize("lv")
   lv.AddTwoLinesAndBitmap("one", "one", Null)
   lv.AddTwoLinesAndBitmap("two", "one", Null)
   lv.AddTwoLinesAndBitmap("three", "one", Null)
   pnl.AddView(lv, 300dip, 120dip, 120dip, 250dip)
   
   cd.AddView(pnl, 77%x, 60%y) ' sizing relative to the screen size is probably best
   ret = cd.Show("B4A Custom Dialog", "Yes", "No", "Maybe", Bmp)   
   ToastMessageShow(ret,True)
End Sub

Sub btn1_Click
   lbl1.Text = "Pressed!"
   lbl1.Color = Colors.Black
   ToastMessageShow("Pressed!", False)      
End Sub




here ist what i changed it to:

B4X:
Sub Sprache

    Do While Langu=""


   Dim cd As CustomDialog2
   Dim pnl As Panel
   pnl.Initialize("pnl")
   Dim bgnd As ColorDrawable
   bgnd.Initialize(Colors.White, 5dip)
   pnl.Background = bgnd
   Dim langbtn1 As Button
   Dim langbtn2 As Button
   langbtn1.Initialize("langbtn1")
   langbtn2.Initialize("langbtn2")
   langbtn1.Text = "Deutsch"
   langbtn2.Text = "Englisch"
   pnl.AddView(langbtn1, 25dip, 50dip, 90dip, 50dip)
   pnl.AddView(langbtn2, 125dip, 50dip, 90dip, 50dip)
   lbl1.Initialize("Bitte eine Sprache wählen. Please select language.")
   pnl.AddView(lbl1, 80dip, 100dip, 120dip, 60dip)
   
   cd.AddView(pnl, 77%x, 60%y) ' sizing relative to the screen size is probably best
   ret = cd.Show("Sprache", "OK", "", "", BMP)      
    ToastMessageShow("Language is "&Langu,True)
   
    Loop   
   
   
End Sub

Sub langbtn1_Click
   lbl1.Text = "Deutsch gewält"
   lbl1.Color = Colors.Blue
   ToastMessageShow("Ok", False)
   Langu="D"
End Sub

Sub langbtn2_Click
   lbl1.Text = "Englisch gewält"
   lbl1.Color = Colors.Blue
   ToastMessageShow("Ok", False)
   Langu="E"
End Sub


as in the sample, bmp is dimmed in process_globals. dialog-lib ist loaded. the Langu-Var is dimmed as char in process_globals.

the two buttons langbtn seem not to trigger langbtn_click - subs (1 and 2) when clicked. and i have no idea why. i am sure it is something easy and beginners-like-error - but i dont find it.

thank you!
 

christianK

Member
Licensed User
Longtime User
thx

thank you so much. this works great.

but as i said above, i try to learn with the code, so, if you have a minute, could you explain why my code s*cks and your edition works?
i see two main differences. first you renamed the buttons. is "langbtn1" not a propper name?
second ist the Do While langu="" part, which you moved down. in fact, i had this command right over the ret = cd.Show - line as you have it now - and it didnt work. so i tried to repeat the dim and initialize-wich every loop (this was the code i posted here)

so in fact, i dont see, why it works now and didnt before
BUT of course thank you so much for the fast answer!


edit:

ok, i think i got it:
you call the sub wir CallSubDelayed. so i did read now about and insert it in my code, and it works.
i called the "sprache"-sub just by typing "sprache". i think, this is the important one.

thank you again!
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…