Get currently active or ontop view id or name

aubete

Member
Licensed User
Longtime User
Hi!

I new in b4a, ant try to create a simple application.

i need to use a label ant that label's text change from database. The datas from database shown an on the fly created listview. But i press a back button (eg cancel) on listview, the all program is go background. I found a snipplet to handle the back button, but i dont know how to knpw what view is ontop or active

My theory is:

if the back button is pressed, i check witch view is on top, (in this case the "on the fly" created listview) and i remove it. if no "on the fly" created view on main layout, i'm tell the system kick my program to background.

my code:

This sub fill the listview from database. (theoretically, my db is empty)

B4X:
Sub partlist_Click
   Dim selsom As ListView
   
   selsom.Initialize("selsom_click")
   Activity.AddView(selsom,5,5,100%x -5dip,100%y -5dip)

   Dim Cursor1 As Cursor
    Cursor1 = db.ExecQuery("SELECT nev, ROWID from partner")
   If Cursor1.RowCount > 0 Then
       For i = 0 To Cursor1.RowCount - 1
           Cursor1.Position = i
           selsom.AddSingleLine(Cursor1.GetInt("ROWID") & "-" & Cursor1.GetString("nev"))
       Next
      selsom.AddSingleLine("Add new...")
   Else
      ToastMessageShow("Empty database, use add new",True)
      selsom.AddSingleLine("Add new...")
   End If
   Cursor1.Close
   selsom.BringToFront
   selsom.Color = Colors.Black
   selsom.SingleLineLayout.Label.TextColor = Colors.White
End Sub

Thanks!

Aubete
 

aubete

Member
Licensed User
Longtime User
I recommend you to use several activities instead. This way the back button will work automatically.

Hi!

Thanks the answer. But, you say, i need to create an activity, to show a selection list? That's not wasting the resources? in this case (in my mind) i open on top of my main layout a panel, with list, if empty, i open an add form ontop of my selection list. This is 3 activity. I understand right?

Anyway i see that method. Thanks.
 
Upvote 0

aubete

Member
Licensed User
Longtime User
Hi!

I try the multi activity mode, but i have a some problem. I declare some variables in process_global in first activity. (using in all modules) Eg a SQL. Initialized in first activity activity_create sub if first create. i declare a valasz variable for result in second activity process_globals.

The sql unreachable from second activity and the valasz is unreachable for first activity.

First (main) activity:

B4X:
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
   Dim lang As String
   Dim db As SQL
End Sub

Second activity:

B4X:
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
   Dim valasz As String
   
End Sub

The compilation result:

B4X:
Parsing code.                           Error
Error parsing program.
Error description: Undeclared variable 'valasz' is used before it was assigned any value.
Occurred on line: 120
If valasz = "" Then

or

B4X:
Parsing code.                           Error
Error parsing program.
Error description: Undeclared variable 'db' is used before it was assigned any value.
Occurred on line: 27
Cursor1 = db.ExecQuery("SELECT nev, ROWID from partner")

What doing wrong?


Aubete
 
Upvote 0
Top