Android Example Inputlist with images

hi

for one of my project, i needed an input list that includes images and i was thinking of using clv for that, but i really wanted to use the native input list so with CSBuilder it is very simple to archive.

have fun!

Screenshot_20180413-134929.jpg
 

Attachments

  • InputListImage.zip
    15.1 KB · Views: 548
Last edited:

Mahares

Expert
Licensed User
Very nice example @ilan. The only thing I would change if I was doing it, is eliminate the ShortCur list and use this code:
B4X:
InputListAsync(longCur, "Select Currency", -1, True)
    Wait For InputList_Result (Index As Int)
    If Index <> DialogResponse.CANCEL Then
        Dim MySelection As String=longCur.Get(Index)
        MySelection=MySelection.SubString2(MySelection.IndexOf("(")+1,MySelection.IndexOf(")"))
        Log("Selected Currency is: " & MySelection)  'yields same result as Ilan's
    End If
 

ilan

Expert
Licensed User
Very nice example @ilan. The only thing I would change if I was doing it, is eliminate the ShortCur list and use this code:
B4X:
InputListAsync(longCur, "Select Currency", -1, True)
    Wait For InputList_Result (Index As Int)
    If Index <> DialogResponse.CANCEL Then
        Dim MySelection As String=longCur.Get(Index)
        MySelection=MySelection.SubString2(MySelection.IndexOf("(")+1,MySelection.IndexOf(")"))
        Log("Selected Currency is: " & MySelection)  'yields same result as Ilan's
    End If

the reason i have 2 lists is i use those currencies in other scenarios so i think it is more readable like this but as long as it works for you its ok :)
 
Last edited:

Jorge M A

Well-Known Member
Licensed User
Thank you very much @ilan for sharing this interesting and useful code on InputListAsync and at the same time of the CSBuilder!
Since I was not able to decipher how did you get the constant factors of height and width of the image :(, I thought it appropriate to use the technique that @Erel suggests in this tutorial, to not distort the image.
Do you think that is correct?

B4X:
Dim bmp As Bitmap
    For x = 0 To longCur.Size-1
        Dim cs As CSBuilder
        'Original -> cs.Initialize.Image(LoadBitmap(File.DirAssets,"flags/cur" & x & ".png"),Activity.Width*0.07,Activity.Height*0.0225,True).Color(Colors.Black).Pop

        bmp = LoadBitmapResize(File.DirAssets, "flags/cur" & x & ".png", 24dip, 24dip, True)
        cs.Initialize.Image( bmp, bmp.Width, bmp.Height, True).Color(Colors.Black).Pop
        
        cs.Color(Colors.Black).Append("     " & longCur.Get(x)).PopAll
        longCur.Set(x,cs)
    Next

Thanks again!
 

ilan

Expert
Licensed User
Thank you very much @ilan for sharing this interesting and useful code on InputListAsync and at the same time of the CSBuilder!
Since I was not able to decipher how did you get the constant factors of height and width of the image :(, I thought it appropriate to use the technique that @Erel suggests in this tutorial, to not distort the image.
Do you think that is correct?

B4X:
Dim bmp As Bitmap
    For x = 0 To longCur.Size-1
        Dim cs As CSBuilder
        'Original -> cs.Initialize.Image(LoadBitmap(File.DirAssets,"flags/cur" & x & ".png"),Activity.Width*0.07,Activity.Height*0.0225,True).Color(Colors.Black).Pop

        bmp = LoadBitmapResize(File.DirAssets, "flags/cur" & x & ".png", 24dip, 24dip, True)
        cs.Initialize.Image( bmp, bmp.Width, bmp.Height, True).Color(Colors.Black).Pop
     
        cs.Color(Colors.Black).Append("     " & longCur.Get(x)).PopAll
        longCur.Set(x,cs)
    Next

Thanks again!

with my code, it should be shown the same on all devices because the size is related to the screen size this is the zoom effect where everywhere the app looks the same.
this is not the best way to do. if you have a bigger screen you can do more but i find it much nicer to work like this. and until now i had no complains so my apps had no issues with a button is outside the frame or stuff like that because i use always the size related to the screen. i created an app in b4j where it is much simpler to get all x,y left, top of a view the is calculated to the screen size and i paste it into the designer script.
 
Top