Android Tutorial ScrollView example

ComposerB4A

Member
Licensed User
Longtime User
Hi to all, one question please, ¿how to identy the image that is selected?
because, each "iv" is new in code and without reference public:
For i = 0 To Bitmaps.Size - 1
Dim iv As ImageView 'create an ImageView for each bitmap
iv.Initialize("") 'not interested in any events so we pass empty string.
Dim bd As BitmapDrawable
bd.Initialize(Bitmaps.Get(i))
iv.Background = bd 'set the background of the image view.
'add the image view to the scroll bar internal panel.
SV1.Panel.AddView(iv, 5dip, 5dip + i * 200dip, SV1.Width - 10dip, 190dip)
Next
 

klaus

Expert
Licensed User
Longtime User
iv.Initialize("") 'not interested in any events so we pass empty string.
Are you sure ?
To get the selected image you need an event !
So you must modify your line into.
iv.Initialize("iv")
and use the iv_Click event.
B4X:
Sub iv_Click
    Dim imv as ImageView
   
    imv = Sender
 

eps

Expert
Licensed User
Longtime User

Something like the code in this post, from this thread. http://www.b4x.com/android/forum/threads/scrollview-example.6612/#post-58277
 

systems1

Member
Licensed User
Longtime User
Is there any option to show the scroll bar every time?
 

Rahul333

New Member
So if i cannot show the scroll bar every time then i have to scroll down the scroll bar automatically when i click radiobutton.
Suppose i have 10 questions with 3 radio buttons as the options for answer. I have created 10panels for 10question each. User can see only 4questions in the page. He need to scroll down to answer more questions.
But he cant make out that there is a scroll bar and there are more questions.
So is there any option to automatically scroll down the scroll bar when user clicks any radiobutton of 4th question, 8th question likewise using basic4android
 
Last edited:

GMan

Well-Known Member
Licensed User
Longtime User
How can i get the pictures from DirAssets?
B4X:
imagesFolder = File.DirRootExternal & "/DCIM/Pictures"
This one won't work:
B4X:
imagesFolder = File.DirAssets

Error:
Images folder not found: AssetsDir
 
Last edited:

GMan

Well-Known Member
Licensed User
Longtime User
Hoi Klaus.
it's this:
B4X:
imagesFolder = File.DirAssets

And here the whole Sub:
B4X:
Sub LoadImages
    Bitmaps.Initialize
    Dim files As List
    Dim imagesFolder As String
    imagesFolder = File.DirAssets

    If File.Exists(imagesFolder, "") = False Then
        ToastMessageShow("Images folder not found: " & CRLF & imagesFolder, True)
        Return
    End If
    files = File.ListFiles(imagesFolder) 'get all files in this folder
    For i = 0 To files.Size - 1
        DoEvents 'required for the ProgressDialog animation
        Dim f As String
        f = files.Get(i)
        If f.ToLowerCase.EndsWith(".jpg") Then
            Dim b As Bitmap
            b.InitializeSample(imagesFolder, f, 200dip, 200dip) 'load the jpeg file and subsample it if it is too large.
            Bitmaps.Add(b) 'add the bitmap to the bitmaps list.
            If Bitmaps.Size > 50 Then Exit 'limit it to 50 images
        End If
    Next
    ToastMessageShow("Found " & Bitmaps.Size & " images", True)
End Sub
 

klaus

Expert
Licensed User
Longtime User
Try this:
B4X:
Sub LoadImages
    Bitmaps.Initialize
    Dim files As List
    Dim imagesFolder As String
    imagesFolder = File.DirAssets

    files = File.ListFiles(imagesFolder) 'get all files in this folder
   
    If files.IsInitialized = False Then
        ToastMessageShow("Images folder not found: " & CRLF & imagesFolder, True)
        Return
    End If

    For i = 0 To files.Size - 1
        DoEvents 'required for the ProgressDialog animation
        Dim f As String
        f = files.Get(i)
        If f.ToLowerCase.EndsWith(".jpg") Then
            Dim b As Bitmap
            b.InitializeSample(imagesFolder, f, 200dip, 200dip) 'load the jpeg file and subsample it if it is too large.
            Bitmaps.Add(b) 'add the bitmap to the bitmaps list.
            If Bitmaps.Size > 50 Then Exit 'limit it to 50 images
        End If
    Next
    ToastMessageShow("Found " & Bitmaps.Size & " images", True)
End Sub

I'm afraid that DirAssets is a special folder.
Anyway, DirAssets always exists !
 

GMan

Well-Known Member
Licensed User
Longtime User
Hoi Klaus,

As my Grandma always said: you don't need to know anything, but: you have always to know who you can ask
So Dank u wel - this works perfect.

And yes, the DirAssets is a special one. i knowed that, but didnt remember in which cases this is special and how to solve.
For showing 3 to 5 pictures i wouldnt like to install the app to /create a additional sd-card folder
 

GMan

Well-Known Member
Licensed User
Longtime User
She did it the "old" way: talking with people in realtime - face-to-face.
Unbelievable, but thats the way they communicated
 

gehrlekrona

Member
Licensed User
Longtime User
I am using this sample with the Scrollview and it works great. Like nad I want to do something with the image that I clicked but can't seem to get it to work. I can get the tag if I set it to iv.tag=i but I can't get the filename. What I want to do is to click the image, load it and view it in the full size.
Anybody?
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…