I want to create a class for my dialogs, but I don't know how to get the result of my dialog, from the class to the activity like in this code, from the dialogs lib demo. As you can see, the result is in the same sub, like a return from a function:
I don't know how to code this in a class.Can someone give-me a clue?
I can get a result like this using this code, not recommended as it stops the thread at the while loop. But it does what I need. Wrong way.
If I try to code the correct way, without blocking the thread, it would like this:
"Message" is a sub at the Main activity:
This way it works, but the program flow is more complicated, because the return is in another sub.
I want to use like in the Dialogs lib, or my example above, with the loop, where the return of the class is is the same sub, top down.
How can I make this?
Thank you for any help.
B4X:
Sub btnInput_Click
Dim Id As InputDialog
Id.Input = ""
Id.Hint = "Enter some text!"
Id.HintColor = Colors.ARGB(196, 255, 140, 0)
ret = DialogResponse.CANCEL
ret = Id.Show("Input the required text", "B4A Input Dialog", "Yes", "No", "Maybe", Bmp)
ToastMessageShow(ret & " : " & Id.Input, False)
End Sub
I don't know how to code this in a class.Can someone give-me a clue?
I can get a result like this using this code, not recommended as it stops the thread at the while loop. But it does what I need. Wrong way.
B4X:
public Sub show
pnl.Initialize("pnl")
pnl.Color=Colors.White
ed.Initialize("")
ed.TextColor=Colors.Black
Dim b1 As Button
b1.Initialize("b1")
pnl.AddView(ed,10dip,10dip,200dip,60dip)
pnl.AddView(b1,10dip,100dip,100dip,50dip)
mActivity.AddView(pnl,5%x,25%x,90%x,50%x)
btt=0 'this is defined at class globals
Do While btt=0
DoEvents
Loop
Return ed.Text
End Sub
Sub b1_click
Dim w As Button
w=Sender
ret = ed.Text
pnl.RemoveView
btt=1
End Sub
If I try to code the correct way, without blocking the thread, it would like this:
B4X:
public Sub show
pnl.Initialize("pnl")
pnl.Color=Colors.White
ed.Initialize("")
ed.TextColor=Colors.Black
Dim b1 As Button
b1.Initialize("b1")
pnl.AddView(ed,10dip,10dip,200dip,60dip)
pnl.AddView(b1,10dip,100dip,100dip,50dip)
mActivity.AddView(pnl,5%x,25%x,90%x,50%x)
btt=0 'this is defined at class globals
End Sub
Sub b1_click
ret = ed.Text
pnl.RemoveView
CallSub(Main,"Message")
End Sub
"Message" is a sub at the Main activity:
B4X:
...
Dim class as MyClass
...
class.initialize()
...
Sub Message()
Log(class.ret)
End Sub
This way it works, but the program flow is more complicated, because the return is in another sub.
I want to use like in the Dialogs lib, or my example above, with the loop, where the return of the class is is the same sub, top down.
How can I make this?
Thank you for any help.