Android Question Why does this Code work?

Reminisce

Active Member
I use this sub to parse a json from my Rest API and then load it into my Customlistview.

Code:
Sub loadlvfeed
Dim parser As JSONParser
parser.Initialize(feedresponse)
feedresponselist= parser.NextArray
feedresponsemap.Initialize
                
    Dim imgmap,m As Map
    Dim pnl As Panel
    Dim imgpostimage As ImageView
    Dim videoplayer As VideoView
    Dim videoplayerlayout As VideoViewRelativeLayout
    Dim pnlvholder As Panel
    imgmap.Initialize
    m.Initialize
                
For i = 0 To feedresponselist.Size - 1
    feedresponsemap = feedresponselist.Get(i)
    Dim user_profilepicture_thumb As String = feedresponsemap.Get("user_profilepicture_thumb")
    Dim post_content As String = feedresponsemap.Get("post_content")
    Dim post_id As String = feedresponsemap.Get("post_id")
    Dim post_date As String = feedresponsemap.Get("post_date")
    Dim user_verifiedaccount As String = feedresponsemap.Get("user_verifiedaccount")
    Dim user_title As String = feedresponsemap.Get("user_title")
    Dim post_like As Int= feedresponsemap.Get("post_like")
    Dim post_type As String = feedresponsemap.Get("post_type")
    Dim post_media_content As String = feedresponsemap.Get("post_media_content")
    Dim user_username As String = feedresponsemap.Get("user_username")
    Dim post_user_id As String = feedresponsemap.Get("post_user_id")
    post_date = du.FormatDateTime(DateTime.Now, Bit.Or(du.FORMAT_SHOW_WEEKDAY, du.FORMAT_SHOW_DATE))
                        
    If user_verifiedaccount = 1 And user_title <> "" Then
        user_title = user_title
    End If
                        
    If user_verifiedaccount = 0  Then
        user_title = "Unverified"
    End If
                        
    If user_verifiedaccount = 1 And user_title  = "" Then
        user_title = "Verified"
    End If
                            
    If lvmenufeed.thesizer = 0  And  post_type = postype(1) And loadoldpost = False Then
        lvmenufeed.Add(feedpostpanel(user_profilepicture_thumb,user_title,user_username,post_content,post_user_id,post_date,post_id,post_like,lvmenufeed.AsView.Width,20%y),feedpostpanelheight,Null)
    Else If lvmenufeed.thesizer <> 0  And  post_type =  postype(1) And loadoldpost =False Then
            lvmenufeed.InsertAt(0,feedpostpanel(user_profilepicture_thumb,user_title,user_username,post_content,post_user_id,post_date,post_id,post_like,lvmenufeed.AsView.Width,20%y),feedpostpanelheight,Null)
            Else If lvmenufeed.thesizer <> 0  And  post_type =  postype(1) And loadoldpost =True Then
            lvmenufeed.InsertAt(lvmenufeed.thesizer,feedpostpanel(user_profilepicture_thumb,user_title,user_username,post_content,post_user_id,post_date,post_id,post_like,lvmenufeed.AsView.Width,20%y),feedpostpanelheight,Null)
    
            
    Else        If lvmenufeed.thesizer = 0  And  post_type = postype(2) Then
                lvmenufeed.Add(feedimagepostpanel(user_profilepicture_thumb,post_media_content,user_title,user_username,post_content,post_user_id,post_date,post_id,post_like,lvmenufeed.AsView.Width,imagepostpanelheight),imagepostpanelheight,Null)
            Else If lvmenufeed.thesizer <> 0  And  post_type =  postype(2) Then
                lvmenufeed.InsertAt(0,feedimagepostpanel(user_profilepicture_thumb,post_media_content,user_title,user_username,post_content,post_user_id,post_date,post_id,post_like,lvmenufeed.AsView.Width,imagepostpanelheight),imagepostpanelheight,Null)
        Else If lvmenufeed.thesizer <> 0  And  post_type =  postype(2) And loadoldpost =True Then
            lvmenufeed.InsertAt(lvmenufeed.thesizer,feedimagepostpanel(user_profilepicture_thumb,post_media_content,user_title,user_username,post_content,post_user_id,post_date,post_id,post_like,lvmenufeed.AsView.Width,imagepostpanelheight),imagepostpanelheight,Null)
        
        Else        If lvmenufeed.thesizer = 0  And  post_type = postype(3) Then
            lvmenufeed.Add(feedvideopostpanel(user_profilepicture_thumb,post_media_content,user_title,user_username,post_content,post_user_id,post_date,post_id,post_like,lvmenufeed.AsView.Width,videopostpanelheight),videopostpanelheight,Null)
        Else If lvmenufeed.thesizer <> 0  And  post_type =  postype(3) Then
            lvmenufeed.InsertAt(0,feedvideopostpanel(user_profilepicture_thumb,post_media_content,user_title,user_username,post_content,post_user_id,post_date,post_id,post_like,lvmenufeed.AsView.Width,videopostpanelheight),videopostpanelheight,Null)
        Else If lvmenufeed.thesizer <> 0  And  post_type =  postype(3) And loadoldpost =True Then
            lvmenufeed.InsertAt(lvmenufeed.thesizer,feedvideopostpanel(user_profilepicture_thumb,post_media_content,user_title,user_username,post_content,post_user_id,post_date,post_id,post_like,lvmenufeed.AsView.Width,videopostpanelheight),videopostpanelheight,Null)
        End If
                    
        ''reset the loadmore boolean into false
        
        If post_type = postype(3) Then
            pnl = lvmenufeed.GetPanel(0)
            pnlvholder = pnl.GetView(11)
            videoplayer.Initialize("")
            videoplayer= pnlvholder.GetView(0)
            videoplayer.LoadVideo("http",Starter.serverlink&"uservideos/"&videoplayer.Tag)
            'videoplayer.MediaControllerEnabled = False
            'videoplayer.Play
        End If
        
        
        'If the post Is an image, get the image link from tag And download
            If post_type = postype(2) Then
            pnl = lvmenufeed.GetPanel(0)
            imgpostimage.Initialize("")
            imgpostimage= pnl.GetView(11)
            m.Put(imgpostimage,Starter.serverlink&"userimages/"&imgpostimage.Tag)
            Log(imgpostimage.Tag)
        End If
        
        ''/insert the imgprofilepic tag and add to map then download the profilepictures after getting the index and download it..
        '//get the profile picture link and load it               
        Dim pnl2 As Panel
        pnl2 = lvmenufeed.GetPanel(0)
        Dim imgprofpic2 As ImageView = pnl2.GetView(1)
        imgmap.Put(imgprofpic2,Starter.serverlink&"userprofilepictures/"&imgprofpic2.Tag)
    
Next
        

loadoldpost = False

CallSubDelayed2(ImageDownloader2,"Downloadimg",imgmap)
CallSubDelayed2(ImageDownloader,"Download",m)

        
End Sub

The highlighted parts causes an error whenever I use lvmenu.getpanel(i) instead of the lvmenu.getpanel(0).

Since this code is inside a for loop, is it not suppose to check for every panel using "i" instead of "0".?
 

LucaMs

Expert
Licensed User
Longtime User
1580972275277.png


Maybe because you're lucky?

(sorry, today I'm very angry... without reasons!!!)
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
maybe you have less panels than json records of that type?

hard to tell/guess without seeing everything
 
Upvote 0
Top