Italian APP leggere 5 xml file con path diverse e caricare LISTVIEW

Lionsoft

Member
Ciao ragazzi innanzitutto complimenti per il forum.
Sono alle prime armi con B4A ma un buon programmatore VISUAL BASIC.
Ho la necessita di creare un APP con una TABHOST con 5 SCELTE e una LISTVIEW
ogni volta che TABHOST TabHost1_TabChanged cambio un percorso path di un file XML e lo carico nella LISTVIEW1. praticamente ho 5xmlfile con stesso DATASET ma con DATI DIVERSI.
Ho quasi completato l 'app ma i dati riesco a caricarli solo una volta quando cambio TAB mi da sempre CONNECTION ERROR

Vi ALLEGO IL CODICE
XML READ:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim Parser As SaxParser
    Dim hc As OkHttpClient
    Dim req As OkHttpRequest
    Dim SiteToRead As String
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim ID As String
    Dim POSTAZIONILIST As ListView
    Dim tabhost1 As TabHost
    Dim NOMEPOSTAZIONE As String
    Dim NUMOPE As String
    Dim OPERATORE As String
    Dim LAVORAZIONI As String
    Dim Record As String
    Dim BUILDER As StringBuilder
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Activity.LoadLayout("main")
    Activity.Title = "IL MIO TURNO"
    tabhost1.AddTab ("6/12","PAGINA1")
    tabhost1.AddTab ("12/18","pagina2")
    tabhost1.AddTab ("18/24","pagina3")
    tabhost1.AddTab ("24/6","pagina4")
    tabhost1.AddTab ("CRONO","pagina5")
    

    POSTAZIONILIST.Width = 100%x
    POSTAZIONILIST.Height = 100%y
    
    'GetRSS_StreamFinish(True,1)
    
End Sub
Sub TabHost1_TabChanged
    POSTAZIONILIST.Clear 'azzero la view
    If tabhost1.CurrentTab = 0 Then
    SiteToRead= "http://odmturni.altervista.org/wp-content/ODM/APP612.xml"
    End If
    If tabhost1.CurrentTab = 1 Then
        SiteToRead= "http://odmturni.altervista.org/wp-content/ODM/APP1218.xml"
    End If
    If tabhost1.CurrentTab = 2 Then
        SiteToRead= "http://odmturni.altervista.org/wp-content/ODM/APP1218.xml"
    End If
    If tabhost1.CurrentTab = 3 Then
        SiteToRead= "http://odmturni.altervista.org/wp-content/ODM/APP246.xml"
    End If


    Parser.Initialize
    hc.Initialize("hc")
    req.InitializeGet(SiteToRead)
    hc.Execute(req,1)

    
    GetRSS_StreamFinish(True,1)
    
    

    
End Sub

Sub hc_ResponseSuccess(Response As OkHttpResponse, TaskId As Int)

    Response.GetAsynchronously("GetRSS", File.OpenOutput(File.DirInternal, "/XML.xml", False), True, TaskId)
            
End Sub
Sub hc_ResponseError(Response As OkHttpResponse, Reason As String, StatusCode As Int, TaskId As Int)

    If Response <> Null Then

        MsgboxAsync( Response.ErrorResponse, "Connection Error")
      
        Response.Release
                            
    End If
                
End Sub

Sub GetRSS_StreamFinish(Success As Boolean, TaskId As Int)

    If Success = False Then

        MsgboxAsync(LastException.Message, "Error")

        Return
    End If
                
    Dim In As InputStream
    
    In = File.OpenInput(File.DirInternal, "/XML.xml")

    Parser.Parse(In, "Parser")

    In.Close
    'File.Delete(File.DirInternal,"/XML.xml")
                
End Sub

Sub Parser_StartElement(Uri As String, Name As String, Attributes As Attributes)
                
End Sub

Sub Parser_EndElement(Uri As String, Name As String, Text As StringBuilder)
        
    If Name = "ID" Then
            
        ID = Text.ToString
        
    Else If Name = "NOMEPOSTAZIONE" Then
            
        NOMEPOSTAZIONE = Text.ToString
        
    Else If Name = "NUMOPE" Then
                  
        NUMOPE= Text.ToString
                                        
    Else If Name = "OPERATORE" Then
                            
        OPERATORE = Text.ToString
                                        
    Else If Name = "LAVORAZIONI" Then
                            
        LAVORAZIONI = Text.ToString

    End If
                
    Record =    "NUMERO OPERATORI : " & NUMOPE & CRLF & "OPERATORE: " & OPERATORE & CRLF & "LAVORAZIONI: " & LAVORAZIONI
                
    If Name = "LAVORAZIONI" Then

        POSTAZIONILIST.TwoLinesLayout.ItemHeight = 140dip
        POSTAZIONILIST.TwoLinesLayout.SecondLabel.Height = 80dip
                
        POSTAZIONILIST.AddTwoLines(NOMEPOSTAZIONE, Record)
                            
    End If
                
End Sub
Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
 

Lionsoft

Member
Ciao ragazzi finalmento ho risolto il problema di caricare i file Xml...adesso però ho un altro problema...
Quando modifico il file sul server e ricarico l xml dall app non vedo la versione aggiornata del file ma la vecchia come se ci fosse una cache web che salva il file.
Ho provato a cambiare anche metodo e usare il POST che normalmente non salva la cache
req.InitializePost2(SiteToRead," ".GetBytes("UTF8"))
ma continuo ad avere lo stesso problema.
Aiutatemi XD
Grazie
 

Sagenut

Expert
Licensed User
Longtime User
@Lionsoft
Molto bene se hai risolto da solo.
Sarebbe meglio se tu potessi descrivere quale era l'errore/problema e come lo hai risolto.
Questo aiuterà altri utenti ,che potrebbero avere il tuo stesso problema, a trovare una soluzione. ;)
 
Top