B4A Library [Library] B4aGridView v3.80

Shahid Saeed

Active Member
Licensed User
Longtime User
A new bug with GridView.TAG.

I am getting the following error when using Retrieving GridView.TAG:-
B4X:
videos_gridview_itemclick (java line: 499)
java.lang.ClassCastException: it.giuseppe.salvi.gridview.library.core.adapter.GridViewAdapterWrapper$ViewHolder cannot be cast to anywheresoftware.b4a.objects.collections.Map$MyMap
    at com.prcamels.videos._gridview_itemclick(videos.java:499)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:163)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:159)
    at it.giuseppe.salvi.gridview.library.core.GridViewActivityWrapper$1.onItemClick(GridViewActivityWrapper.java:153)
    at it.giuseppe.salvi.gridview.library.core.widget.gridview.GridViewWrapper.onItemClick(GridViewWrapper.java:86)
    at android.widget.AdapterView.performItemClick(AdapterView.java:298)
    at android.widget.AbsListView.performItemClick(AbsListView.java:1086)
    at android.widget.AbsListView$PerformClick.run(AbsListView.java:2855)
    at android.widget.AbsListView$1.run(AbsListView.java:3529)
    at android.os.Handler.handleCallback(Handler.java:615)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4745)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    at dalvik.system.NativeStart.main(Native Method)
java.lang.ClassCastException: it.giuseppe.salvi.gridview.library.core.adapter.GridViewAdapterWrapper$ViewHolder cannot be cast to anywheresoftware.b4a.objects.collections.Map$MyMap

This is what I am doing:-

B4X:
Dim video_title As String = album_videos.Get("video_title")
Dim video_image As String = album_videos.Get("video_image")
Dim video_id As String = album_videos.Get("video_id")
Dim vidmap As Map
vidmap.Initialize
vidmap.Put("video_id",video_id)
GridView.Tag = vidmap
GridView.AddImageFromWeb(video_image)
GridView.SetText(vid_row, video_title)

Sub GridView_ItemClick(Position As Int, Tag As Object, Value As Object)  
    posSelected = Position    
    Dim vidmap As Map = Tag
    Log(vidmap.Get("video_id"))   
End Sub

I have tried another approach and I am getting the following error:-

B4X:
java.lang.NullPointerException
    at it.giuseppe.salvi.gridview.library.core.GridViewActivityWrapper.getTag(GridViewActivityWrapper.java:253)
    at com.prcamels.videos._gridview_itemclick(videos.java:503)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:163)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:159)
    at it.giuseppe.salvi.gridview.library.core.GridViewActivityWrapper$1.onItemClick(GridViewActivityWrapper.java:153)
    at it.giuseppe.salvi.gridview.library.core.widget.gridview.GridViewWrapper.onItemClick(GridViewWrapper.java:86)
    at android.widget.AdapterView.performItemClick(AdapterView.java:298)
    at android.widget.AbsListView.performItemClick(AbsListView.java:1086)
    at android.widget.AbsListView$PerformClick.run(AbsListView.java:2855)
    at android.widget.AbsListView$1.run(AbsListView.java:3529)


    at android.os.Handler.handleCallback(Handler.java:615)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4745)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    at dalvik.system.NativeStart.main(Native Method)
java.lang.NullPointerException

This is what I am doing in Second Approach:-

B4X:
Dim video_title As String = album_videos.Get("video_title")
Dim video_image As String = album_videos.Get("video_image")
Dim video_id As String = album_videos.Get("video_id")
Dim vidmap As Map
vidmap.Initialize
vidmap.Put("video_id",video_id)
GridView.Tag = vidmap
GridView.AddImageFromWeb(video_image)
GridView.SetText(vid_row, video_title)

Sub GridView_ItemClick(Position As Int, Tag As Object, Value As Object)  
    posSelected = Position
    Dim vid As PhotoGridView = Sender
    Dim vidmap As Map = vid.Tag
    Log(vidmap.Get("video_id"))   
End Sub
 

lonleystar

Well-Known Member
Licensed User
Longtime User
Hi Shahid and all, the B4AGridView is updated to v3.25.

fix: Tag and minor bugs, code below.

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

    Dim vid As PhotoGridView = Sender
   
    vidmap.Put("video_id",Position)
   
    vid.Tag = vidmap
   
    posSelected = Position

    GridView.SetText(Position,vid.Tag)
   
    GridView.SetBackgroundImage(Value)
   
End Sub


I'm really sorry for the inconvenience.
 

deltacode

Member
Licensed User
Longtime User
Thanks for the quick update but there is one step forward and two back.

The tag works , the outside text bottom works

Now the bad news
The SetText still updates both panels and even worse now adding images updates both panels where in 3.20 it did at least update the images in the two panels differently and correctly
 

lonleystar

Well-Known Member
Licensed User
Longtime User


Hi, I just added the Text_Bottom_OutSide and fix the tag and minor bugs nothing else.
 

Shahid Saeed

Active Member
Licensed User
Longtime User
Hi guys, anyone who has downloaded the version v 3.25 please re download it I made a mistake is now fix.


sorry for the inconvenience.
I have just downliad the 3.25 update but there are some strange things.

on first load the grid view works fine when press and move to next activity there is an-other grid view but it shows nothing when go back to first activity its show the items of second activity with titles of first activity.

now when i am using the tag option i am getting the following error on item_click

B4X:
java.lang.Exception: Sub gridview_itemclick signature does not match expected signature.
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:177)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:163)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:159)
    at it.giuseppe.salvi.gridview.library.core.GridViewActivityWrapper$1.onItemClick(GridViewActivityWrapper.java:162)
    at it.giuseppe.salvi.gridview.library.core.widget.gridview.GridViewWrapper.onItemClick(GridViewWrapper.java:86)
    at android.widget.AdapterView.performItemClick(AdapterView.java:298)
    at android.widget.AbsListView.performItemClick(AbsListView.java:1086)
    at android.widget.AbsListView$PerformClick.run(AbsListView.java:2855)
    at android.widget.AbsListView$1.run(AbsListView.java:3529)
    at android.os.Handler.handleCallback(Handler.java:615)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4745)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    at dalvik.system.NativeStart.main(Native Method)
java.lang.Exception: Sub gridview_itemclick signature does not match expected signature.
 

lonleystar

Well-Known Member
Licensed User
Longtime User



Hi Shahid,
GridView_ItemClick(Position AsInt, Value AsObject) instead of GridView_ItemClick(Position AsInt, Tag As Object, Value AsObject)

I removed Tag As Object from the evnts

Tag get or sets work fine now.


read the post #166
 

Shahid Saeed

Active Member
Licensed User
Longtime User
Hi Shahid,
GridView_ItemClick(Position AsInt, Value AsObject) instead of GridView_ItemClick(Position AsInt, Tag As Object, Value AsObject)

I removed Tag As Object from the evnts

Tag get or sets work fine now.


read the post #166

Items are getting repeated from one activity to another activity.

after using this GridView_ItemClick(Position AsInt, Value AsObject) the signature error gone.
In Tag instead of video id I am getting the item position not the video_id, or if I use this code I'm getting same video id for all items:

B4X:
Dim video_title As String = album_videos.Get("video_title")
Dim video_image As String = album_videos.Get("video_image")
Dim video_id As String = album_videos.Get("video_id")
Dim vidmap As Map
vidmap.Initialize
vidmap.Put("video_id",video_id)
GridView.Tag = vidmap
GridView.AddImageFromWeb(video_image)
GridView.SetText(vid_row, video_title)

Sub GridView_ItemClick(Position As Int, Tag As Object, Value As Object)  
    posSelected = Position
    Dim vid As PhotoGridView = Sender
    Dim vidmap As Map = vid.Tag
    Log(vidmap.Get("video_id"))  
End Sub
 

Shahid Saeed

Active Member
Licensed User
Longtime User
Instead of going with Tag I have gone through a different process as below and now i am getting the individual Video Id's

I have created a Global List Variable and added the video id to it. and on item_click i have collected the Video ID through item position

B4X:
Sub Process_Globals
    Dim VideoID_TAG As List
End Sub

Sub ParseJSON(json As String)
    Dim parser As JSONParser
    parser.Initialize(json)
   
    Dim root As Map = parser.NextObject
    Dim albums As List = root.Get("albums")
    Dim actAlbum As Int = -1   
    For Each col_albums As Map In albums
        actAlbum = actAlbum +1         
        Dim album_title As String = col_albums.Get("album_title")
        VideoID_TAG.Initialize
        If actAlbum = AlbumID Then       
        Dim Videos As List = col_albums.Get("videos")
            Dim vid_row As Int = -1
            For Each album_videos As Map In Videos
            vid_row = vid_row +1
            Dim video_title As String = album_videos.Get("video_title")
            Dim video_image As String = album_videos.Get("video_image")
            Dim video_id As String = album_videos.Get("youtube_id")            
            VideoID_TAG.Add(video_id)
            'GridView.Tag = vidmap
            GridView.AddImageFromWeb(video_image)
            GridView.SetText(vid_row, video_title)   
            Next           
        Page_title.Text = album_title
        End If       
    Next   
End Sub

Sub GridView_ItemClick(Position As Int, Value As Object)       
    posSelected = Position    
    Log(Position)
    Log(VideoID_TAG.Get(Position))
    YouTube(VideoID_TAG.Get(Position))      
End Sub
 

Shahid Saeed

Active Member
Licensed User
Longtime User
Now the strange thing remains in the new update, If I am moving from one activity to another the items are being repeated on every activity. Even if The activity restarts it has the repeated items.
 

deltacode

Member
Licensed User
Longtime User
Thanks lonelystar, can confirm the pictures are now fixed

The SetText still repeats the text on all views on any panel/activity , can this be fixed ?
 

Shahid Saeed

Active Member
Licensed User
Longtime User
@lonleystar is the above issue fixed? I just want to ask one more thing, when we scroll through GridView, and move between images, it re-loads already loaded images, cannot we just load once and keep the images intact until unless we restart the activity?
 

deltacode

Member
Licensed User
Longtime User
Hi lonleystar

Have you managed to get anywhere with the settext issue ? Once this is fixed i shall be donating for a great library.

Also i noticed on B4APhotoPager that somebody requested to add a bitmap, can that be added to this library as well ?
 

lonleystar

Well-Known Member
Licensed User
Longtime User


Hi, for the settext I'm working to understand how I can do that for the second question yes I'm implementing the same engine like GridView and i'll implement also AddBitmap.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…