B4A Library Popup Menu/List Library

What it does:
Shows an InputList modal dialog and allows the user to select an item from the list and hides on selection of the item.

Why we may need it:
This will eventually become redundant as Erel adds it to the Core library.
I needed to show some popup menus, and experimented with various ideas (panels, inputlist etc) but none were perfect. This should take care of screen size, modality etc in the same way other dialogs do.

How it works:
Nothing great. I just copied the function InputList from the Core library and replaced:
B4X:
b.setSingleChoiceItems(items, CheckedItem, dr);
with
B4X:
b.setItems(items, dr);
So in effect it just removes the RadioButtons from the InputList.

Sample code:

B4X:
   Dim r As List 
   r.Initialize 
   r.AddAll(Array As String("Download","Upload","Share"))
   
   Dim x As id 
   m = x.InputList1(r,"Hello")
   Msgbox(m,"Result")
 

Attachments

  • id.zip
    2.5 KB · Views: 2,494
D

Deleted member 103

Guest
Hi thedesolatesoul,

thanks for sharing.

@Erel
can you the function in the core library add?


Ciao,
Filippo
 

Djembefola

Active Member
Licensed User
Longtime User
Nice.
What i'm missing is setting the Position of the Popup Menu. The inputlist is always centered. Especially on a large tablet i would prefer to show it close to the touch coordinates instead of opening it at a fixed centered position.

Thanks for sharing.
 

thedesolatesoul

Expert
Licensed User
Longtime User
Nice.
What i'm missing is setting the Position of the Popup Menu. The inputlist is always centered. Especially on a large tablet i would prefer to show it close to the touch coordinates instead of opening it at a fixed centered position.

Thanks for sharing.

I have no idea how to do that. But it looks quite hard.
 

Penko

Active Member
Licensed User
Longtime User
I asked because I saw you discussed it a while ago and it may have been added in the meantime.

Thanks for your work!

May I ask that you give it a more sensible name rather than "id". I don't blame you, I just want to help others understand what you've done. To be honest, at the very first reading of your post, when I noticed the "id", it took me about 2 seconds...

Thanks for the work, I already implemented it with your library. By the way, I renamed my local version to InputListEnhanced but was "afraid" to modify the values inside the xml :).
 

frapel

Active Member
Licensed User
Longtime User
:sign0087:

Thanx thanx thanx for "hacking" Erel modal InputList and for sharing with us...
me too I think Erel should add this to Core library 'cause wasn't immediate for me to find this thread...

B4A forum is made of great and hard-working people :icon_clap:
thedesolatesoul, thank you again
 
U

unba1300

Guest
What do we do with the id.jar and id.xml files in order to get this working? Thanks.
 
U

unba1300

Guest
Got it. (Then had to refresh the Libs list and check 'id'). Thank you.
 

CharlesIPTI

Active Member
Licensed User
Longtime User
details

So technically what do you declare the variable 'm' as in your sample
And what is the Type 'id' that x is declared as please ??

Dim r As List
Dim m As UnknownPookiePoo


r.Initialize
r.AddAll(Array As String("Download","Upload","Share"))

Dim x As id
m = x.InputList1(r,"Hello")
Msgbox(m,"Result")
 

thedesolatesoul

Expert
Licensed User
Longtime User

cnicolapc

Active Member
Licensed User
Longtime User
Congratulations for the library was what I needed.
is there a way to get the string value from the list instead of index?
Thank you
Nicola
 

thedesolatesoul

Expert
Licensed User
Longtime User
Congratulations for the library was what I needed.
is there a way to get the string value from the list instead of index?
Thank you
Nicola
Yes, there is, if you define your array of strings separately.

Untested code:
B4X:
Dim Days() As String
Days = Array As String("Sunday", "Monday", "Funday")
Dim r As List 
r.Initialize 
r.AddAll(Days)

Dim x As id 
Dim m as Int
Dim responseString as String
m = x.InputList1(r,"Hello")
Msgbox(m,"Result Integer")
responseString = Days(m)
Msgbox(responseString,"Result String")
 

cnicolapc

Active Member
Licensed User
Longtime User
Hi,
I would like to use it with a sql query but I'm missing something, what is wrong?
Thank you
Nicola
B4X:
Sub BtnGenere_CLick
Dim Gene() As String
Dim r As List 
r.Initialize 
Dim x As id 
Dim m As Int
Dim responseString As String


   
   Dim ValoreGenere As String
   Dim r As List
   r.Initialize 
   
   ListaGenere.Initialize("ListaGenere")
   Cursor1 = Main.Sql1.ExecQuery("SELECT Genere FROM GenereTab Order By Genere ASC")
   For i = 0 To Cursor1.RowCount - 1
        Cursor1.Position = i
      ValoreGenere=Cursor1.GetString("Genere")
      If ValoreGenere.Length >=30 Then
      ValoreGenere=ValoreGenere.SubString2(0,30)&"..."
      End If
      ValoreGenere=ValoreGenere.Replace(Chr(13), " ")
      ValoreGenere=ValoreGenere.Replace(Chr(10), " ")
      
      Gene = Array As String(ValoreGenere)
         
         Next
      r.AddAll(Gene)      
   m = x.InputList1(r,"Hello")
Msgbox(m,"Result Integer")
responseString = Gene(m)
Msgbox(responseString,"Result String")
   

      End Sub
 

thedesolatesoul

Expert
Licensed User
Longtime User
In your case you do not even need an array (its better to have a list), because you dont know what the query will return. By the way, I know nothing about SQL.


B4X:
Sub BtnGenere_CLick
Dim r As List 
r.Initialize 
Dim x As id 
Dim m As Int
Dim responseString As String


    
    Dim ValoreGenere As String
    Dim r As List
    r.Initialize 
    
    ListaGenere.Initialize("ListaGenere")
    Cursor1 = Main.Sql1.ExecQuery("SELECT Genere FROM GenereTab Order By Genere ASC")
    For i = 0 To Cursor1.RowCount - 1
        Cursor1.Position = i
        ValoreGenere=Cursor1.GetString("Genere")
        If ValoreGenere.Length >=30 Then
        ValoreGenere=ValoreGenere.SubString2(0,30)&"..."
        End If
        ValoreGenere=ValoreGenere.Replace(Chr(13), " ")
        ValoreGenere=ValoreGenere.Replace(Chr(10), " ")
        
        Gene = Array As String(ValoreGenere)
        r.Add(Gene)
            
       Next

    m = x.InputList1(r,"Hello")
Msgbox(m,"Result Integer")
responseString = r.Get(m)
Msgbox(responseString,"Result String")
    

        End Sub
 
Top