B4A Library [Library] B4aGridView v3.80

Shahid Saeed

Active Member
Licensed User
Longtime User

You are loading pictures inside Album this is what I am already doing in next activity, first I need to show Album pictures which my code is doing as well. just to what was the concern the pictures are not being displayed in full on right and bottom edges.
 

xor83

Member
Licensed User
Longtime User
Hi lonleystar and thanks for this great library. Your library works great but I am facing one issue or may be I don't know how to do this.
I am showing small resized images as thumbnails in grid and on clicking any of thumbnail my app takes user to detail page where I want to show full size image/wallpaper, for that I need to store some value/details of image like ID which I get when user clicks on thumbnail. Is there any way that I can do this?
 

Shahid Saeed

Active Member
Licensed User
Longtime User

Try the code below:

B4X:
Sub GridView_ItemClick(Position As Int, Value As Object) 
      DetailPage.Position = Position 'Defines position of clicked picture to the next activity
     StartActivity(DetailPage) 'starts the next activity
End Sub

In a similar behavior you can define any value to the next activity.

B4X:
Sub GridView_ItemClick(Position As Int, Value As Object) 
      DetailPage.Position = Position 'Defines position of clicked picture to the next activity
      DetailPage.PictureID = PictureID
      DetailPage.Detail = Detail
     StartActivity(DetailPage) 'starts the next activity
End Sub
 

xor83

Member
Licensed User
Longtime User
Thanks Shahid for your reply.

B4X:
DetailPage.Position = Position

The above line will allow me to get position and thumbnail from grid but not the ID of image which is coming from mysql table.

I want to store my mysql ID so that on details page I make one more http(json) call to get full sized image url and other details
 

Shahid Saeed

Active Member
Licensed User
Longtime User

I think you skipped this code in my last reply:-

B4X:
Sub GridView_ItemClick(Position As Int, Value As Object) 
 DetailPage.Position = Position 'Defines position of clicked picture to the next activity
 DetailPage.PictureID = PictureID 'PictureID value from your MySQL ID
 DetailPage.Detail = Detail 'Detail from your MySQL Detail
StartActivity(DetailPage) 'starts the next activity
End Sub
 

xor83

Member
Licensed User
Longtime User
I am loading 50 image on startup and loop through json data and load image using "AddImageFromWeb" function. Till this point I don't have mysql ID's (though its coming in json data but I don't know how to store them in relation to thumbnails in gridview)

On item click from where should I get "PictureID" data? which is my mysql ID.
 

Shahid Saeed

Active Member
Licensed User
Longtime User

Can you share your code to guide you in the right direction?
 

xor83

Member
Licensed User
Longtime User
On start-up this is where I parse json string and fill images in grid view.
check the variable "pdroid_id" that contains the mysql ID but don't know where to store the ID in relation to gridview thumbnails
My last solution will to use keyvaluestore class to save mysql ID's in relation to gridview position

B4X:
Mylist.Initialize       
       
        JSON.Initialize(JsonResponse)       
        Mylist = JSON.NextArray
       
        For i = 0 To Mylist.Size - 1       
            Map1 = Mylist.Get(i)       
            Dim pdroid_image As String = Map1.Get("path")
            Dim pdroid_id As String = Map1.Get("id")
       
            kvs.PutSimple( i , pdroid_id)
           
            GridView.AddImageFromWeb(pdroid_image)
            'Log( Map1.Get("name") )
        Next


The problem is here:

B4X:
Sub GridView_ItemClick(Position As Int, Value As Object) 

      'DetailPage.image_id
      'DetailPage.i = Position 'Defines position of clicked picture to the next activity     
      StartActivity(DetailPage) 'starts the next activity
End Sub

From where should I get the mysql ID on click?
 

Shahid Saeed

Active Member
Licensed User
Longtime User

You can pass the position value to the next activity and from there you can parse the same picture using the position value you have through JSON

B4X:
Sub GridView_ItemClick(Position As Int, Value As Object)
      DetailPage.image_id = Position
      'DetailPage.i = Position 'Defines position of clicked picture to the next activity    
      StartActivity(DetailPage) 'starts the next activity
End Sub

And on DetailPage Acitivity you can Parse the JSON as below:-

B4X:
Dim PicturePosition = Image_id
Mylist.Initialize            
        JSON.Initialize(JsonResponse)      
        Mylist = JSON.NextArray
      
        For i = 0 To Mylist.Size - 1      
           If PicturePosition = i Then
            Map1 = Mylist.Get(i)      
            Dim pdroid_image As String = Map1.Get("path")
            Dim pdroid_id As String = Map1.Get("id")
      
            kvs.PutSimple( i , pdroid_id)
            End If
            'GridView.AddImageFromWeb(pdroid_image)
            'Log( Map1.Get("name") )
        Next
 

Shahid Saeed

Active Member
Licensed User
Longtime User

You can also try another approach:

B4X:
    JSON.Initialize(JsonResponse)      
        Mylist = JSON.NextArray
         
        For i = 0 To Mylist.Size - 1      
            Map1 = Mylist.Get(i)                  
            If ImageMap.Get("ImageID") = Map1.get("id") Then
            Dim pdroid_image As String = Map1.Get("path")
            Dim pdroid_id As String = Map1.Get("id")
       
            kvs.PutSimple( i , pdroid_id)
            im ImageMap As Map
            ImageMap.Initialize
            ImageMap.Put("Image_ID", pdroid_id)
            GridView.Tag = ImageID
            End If
            'GridView.AddImageFromWeb(pdroid_image)
            'Log( Map1.Get("name") )
        Next
       
       
        Sub GridView_ItemClick(Position As Int, Value As Object)
            Dim ImageID As ImageView = Sender
            Dim ImageMap As Map = ImageID.Tag
         'DetailPage.image_id
         'DetailPage.i = Position 'Defines position of clicked picture to the next activity    
            Main.ClickedImage = ImageID.Tag
         StartActivity(DetailPage) 'starts the next activity
        End Sub

B4X:
        Sub Activity_Create(FirstTime As Boolean)
            Dim ImageMap As Map
            ImageMap = Main.ClickedImage
           
            ylist.Initialize      
       
        JSON.Initialize(JsonResponse)      
        Mylist = JSON.NextArray
         
        For i = 0 To Mylist.Size - 1      
            Map1 = Mylist.Get(i)                  
            If ImageMap.Get("ImageID") = Map1.get("id") Then
            Dim pdroid_image As String = Map1.Get("path")
            Dim pdroid_id As String = Map1.Get("id")
       
            kvs.PutSimple( i , pdroid_id)
              End If
            'GridView.AddImageFromWeb(pdroid_image)
            'Log( Map1.Get("name") )
        Next
        End Sub
 

Shahid Saeed

Active Member
Licensed User
Longtime User
In Your Main Activity you will have to define:-

B4X:
Sub Process_Globals         
    Dim ClickedImage As Map           
End Sub

And if you are loading the GridView in Main Acitivty use it as below:-

B4X:
Sub GridView_ItemClick(Position As Int, Value As Object)
            Dim ImageID As ImageView = Sender
            Dim ImageMap As Map = ImageID.Tag
            'DetailPage.image_id
            'DetailPage.i = Position 'Defines position of clicked picture to the next activity    
            ClickedImage = ImageID.Tag
         StartActivity(DetailPage) 'starts the next activity
        End Sub
 

xor83

Member
Licensed User
Longtime User
Thanks Shahid for your time and help.

Dim ImageID As ImageView = Sender

Above line giving me this error
java.lang.ClassCastException: android.widget.GridView
 

Shahid Saeed

Active Member
Licensed User
Longtime User
Thanks Shahid for your time and help.

Dim ImageID As ImageView = Sender

Above line giving me this error
java.lang.ClassCastException: android.widget.GridView
Try this:-

B4X:
Dim ImageID As PhotoGridView = Sender
 

bluedude

Well-Known Member
Licensed User
Longtime User
Hi,

Just like your photogallery solution this thing throws a Stackoverflow when used in an app. with multiple activities. I have added the gallery as a seperate activity but when running it and adding image from either web or mediastore it throws a stackoverflow and kills the gallery. Below the log:

Initialize ImageLoader with configuration
threadid=1: stack overflow on call to Ljava/util/Collections;.emptyList:L
method requires 4+20+0=24 bytes, fp is 0x41a25314 (20 left)
expanding stack end (0x41a25300 to 0x41a25000)
Shrank stack (to 0x41a25300, curFrame is 0x41a25380)
Exception thrown (Ljava/lang/StackOverflowError while throwing internal exception (Ljava/io/FileNotFoundException
Shutting down VM
threadid=1: thread exiting with uncaught exception (group=0x41b8ed40)
java.lang.StackOverflowError
at java.lang.Throwable.<init>(Throwable.java:67)
at java.lang.Exception.<init>(Exception.java:47)
at java.io.IOException.<init>(IOException.java:44)
at java.io.FileNotFoundException.<init>(FileNotFoundException.java:42)
at android.content.res.AssetManager.openAsset(Native Method)
at android.content.res.AssetManager.open(AssetManager.java:316)
at android.content.res.AssetManager.open(AssetManager.java:290)


at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:246)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(Ph
Message longer than Log limit (4000). Message was truncated.
FATAL EXCEPTION: main
Process: com.thingstank.apps.myapp, PID: 10193
java.lang.StackOverflowError
at java.lang.Throwable.<init>(Throwable.java:67)
at java.lang.Exception.<init>(Exception.java:47)
at java.io.IOException.<init>(IOException.java:44)
at java.io.FileNotFoundException.<init>(FileNotFoundException.java:42)
at android.content.res.AssetManager.openAsset(Native Method)


at android.content.res.AssetManager.open(AssetManager.java:316)
at android.content.res.AssetManager.open(AssetManager.java:290)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:246)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.salvi.library.photo.grid.view.adapter.PhotoGridBaseAdapter.getBitmapFromAssets(PhotoGridBaseAdapter.java:248)
at it.giuseppe.s
Force finishing activity com.thingstank.apps.myapp/.actgrid
Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:1244
 

bluedude

Well-Known Member
Licensed User
Longtime User
And the stop and resume engine also gives and exception error. As said, if I use it in a new project with only a main activity it works fine. In any other app. it crashes.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…