Italian B4I listview - tableview ma come funziona?

LucaMs

Expert
Licensed User
Longtime User
Ok, dovrei andare a dormire ma la voglia di provare a fare il tutto con B4X è troppa (solo che i miei due unici neuroni già dormono 😄)

A dire la verità non ho nemmeno letto il problema, il primo post; ci provo!
Eh, ma se ti faccio una prova io, usando B4X, non comprenderebbe quelle cose di B4i che non conosco, come quel NavigationController, che immagino, guardando il codice, contenga delle "pagine".

Inoltre, tu crei tutta la GUI da codice!


Lucams non so come integrarla sul progetto questa benedetta customlistview.
Il problema è proprio quello che ho appena scritto, che crei tutto da codice!

Suppongo che tu possa caricare un Panel-Pane o come se chiama in B4i - che basta dichiarare come B4XView, in una di quelle Page; fatto questo, in questo Panel carichi un layout CREATO COL DESIGNER, che contiene una xCustomListView (e magari la EditText e la Label).
 

LucaMs

Expert
Licensed User
Longtime User
Nell'esempio allegato (alcune schifezze puoi toglierle o modificarle, come il TextChanged che rende visibile/invisibile il tasto per aggiungere l'ordine, btnAdd) carico il layMain che contiene un Panel, pnlOrdini e all'interno di questo carico il layout layOrdini, che contiene una xCustomListView, una EditText e un Button.

Tu, se ho capito bene, hai delle pagine in quel navigator; metti in una pagina un Panel (o come se chiama in B4i) e caricaci direttamente layOrdini.
 

Attachments

  • xCLV.zip
    10.5 KB · Views: 171

fifiddu70

Well-Known Member
Licensed User
Longtime User
interessante questo esempio, peccato che sia per b4A il che non mi dispiace perchè vorrei sostituire la listview di un mio vecchio progetto b4a proprio con la custom listview, adesso provo a smanettare per il b4i sperando di riuscire al mio intento, io vi carico il mio progetto per farvi capire dove sono arrivato, praticamente si tratta di una app per iphone che voglio fare per preparare la lsita della spesa, esiste un pulsante che ti permette di aggiungere sulla lista i vari prodotti che inserisci e poterli rimuovere dalla lista nel caso di errori, poi un'altro pulsante ti permette di parlare a voce al posto di scrivere il prodotto da tastiera, alla fine devo ancora aggiungere la possibilità di inviare la lista della spesa su un numero whataspp, comunque posto fino a dove sono arrivato e proprio alla listview mi sono bloccato.
B4X:
'Code module
#Region  Project Attributes
    #ApplicationLabel: lista spesa
    #Version: 1.0.0
    'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
    #iPhoneOrientations: Portrait
    #iPadOrientations: Portrait
    #Target: iPhone, iPad
    #ATSEnabled: True
    #MinVersion: 10
    #PlistExtra:<key>NSSpeechRecognitionUsageDescription</key><string>More information here...</string>
    #PlistExtra:<key>NSMicrophoneUsageDescription</key><string>Speech recognition</string>
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public App As Application
    Public NavControl As NavigationController
    Private Page1 As Page
    Dim picker1 As List
    Private pk1 As Picker
    Private web As WebView
    Private imgsplash As ImageView
    Dim timer1 As Timer
    Dim txtordine As TextField
    Private btnaggiungi As Button
    Private TableView1 As TableView
    Private speech As SpeechRecognition
    Private btnStart As Button
    Private btnStop As Button
End Sub

Private Sub Application_Start (Nav As NavigationController)
    'SetDebugAutoFlushLogs(True) 'Uncomment if program crashes before all logs are printed.
    NavControl = Nav
    Page1.Initialize("Page1")
    Page1.Title = "Ordinaquì 1.0"
    Page1.RootPanel.Color = Colors.RGB (6, 82, 140)
    NavControl.ShowPage(Page1)
    pk1.Initialize("pk1")
    web.Initialize("web")
    TableView1.Initialize("TableView1", False)
    Page1.RootPanel.AddView(TableView1, 1%x, 12%y, 98%x, 50%y)
    For i = 1 To 5
    Dim tc As TableCell = TableView1.AddTwoLines("", "")
    tc.IndentationLevel = Rnd(0, 5)
    
    Next
    btnaggiungi.Initialize("btnaggiungi",btnaggiungi.STYLE_SYSTEM)
    btnaggiungi.Text = "AGGIUNGI"
    btnaggiungi.SetBorder(2,Colors.Black,8)
    btnaggiungi.SetShadow(Colors.Black,3,3,1,True)
    btnaggiungi.Color=Colors.LightGray
    btnStart.Initialize("btnStart",btnStart.STYLE_SYSTEM)
    btnStart.Text="PARLA"
    btnStart.SetBorder(2,Colors.Black,8)
    btnStart.SetShadow(Colors.Black,3,3,1,True)
    btnStart.Color=Colors.LightGray
    btnStop.Initialize("btnStop",btnStop.STYLE_SYSTEM)
    btnStop.Text="STOP"
    btnStop.SetBorder(2,Colors.Black,8)
    btnStop.SetShadow(Colors.Black,3,3,1,True)
    btnStop.Color=Colors.LightGray
    
    txtordine.Initialize("txtordine")   
    imgsplash.Initialize("imgsplash")
    timer1.Initialize("timer1",2000)
    timer1.Enabled=True
    
    imgsplash.Bitmap = LoadBitmap( File.DirAssets,"1200splashscreen.jpg")
    Page1.RootPanel.AddView(imgsplash, 0%x, 0%y, 100%x, 89%y)
    Page1.RootPanel.AddView(txtordine, 3%x,1%y,70%x,9%y)
    Page1.RootPanel.AddView(btnaggiungi, 73%x,1%y,26%x,10%y)
    Page1.RootPanel.AddView(web,5%x,11%y,90%x,50%y)
    Page1.RootPanel.AddView(pk1,5%x,65%y,40%x,30%y)
    Page1.RootPanel.AddView(btnStart,5%x,65%y,25%x,9%y)
    Page1.RootPanel.AddView(btnStop,32%x,65%y,25%x,9%y)
    
    picker1.Initialize
    web.Visible=False
    pk1.Visible=False
    
    pk1.SetItems(0,picker1)
    
    picker1.Add("CONAD")
    picker1.Add("EUROSPIN")
    picker1.Add("DESPAR")
    picker1.Add("SIGMA")
    picker1.Add("IL CENTESIMO")
    picker1.Add("LIDL")
    picker1.Add("PAGHI POCO")
    picker1.Add("FAMILA")
    picker1.Add("PENNY")
    picker1.Add("COOP")
    picker1.Add("ESSELUNGA")
    picker1.Add("AUCHAN")
    picker1.Add("A&O")
    picker1.Add("MD")
    picker1.Add("SIMPLY")
    picker1.Add("CARREFOUR")
    
    pk1.Color = Colors.White
    
    web.Visible=False
    speech.Initialize("speech")
End Sub
Sub Speech_AuthorizationStatusChanged (Status As Int)
    If speech.IsAuthorized Then
        Dim lang As String
        If speech.SupportedLanguages.IndexOf(speech.DefaultLanguage) > -1 Then
            lang = speech.DefaultLanguage
        Else
            lang = "en"
        End If
        If speech.SetLanguage(lang) = False Then
            txtordine.Text = "Speech Recognition not available."
        Else
            txtordine.Text = "Ready!"
            
        End If
    Else
        txtordine.Text = "Not authorized..."
    End If
End Sub



Sub btnStart_Click
    speech.StartRecording(True) 'report partial results
    txtordine.Text = "Recording..."
    
End Sub

Sub btnStop_Click
    speech.StopRecording
    
End Sub
Sub Speech_Result (Success As Boolean, IsFinal As Boolean, Texts As List)
    If Success Then
        txtordine.Text = Texts.Get(0)
        
    Else
        txtordine.Text = "Error: " & LastException
    End If
    
End Sub
Sub pk1_ItemSelected (Column As Int, Row As Int)
    If Row = 0 Then
        web.Visible=True
        web.LoadUrl ("https://www.conad.it/ricerca-negozi.html")
    Else If Row = 1 Then
        web.Visible=True
        web.LoadUrl("https://www.eurospin.it/volantino-nazionale/")
    Else If Row = 2 Then
        web.Visible=True
        web.LoadUrl ("https://www.despar.it/it/")
    Else If Row = 3 Then
        web.Visible=True
        web.LoadUrl("https://www.supersigma.com/offerte")
    Else If Row = 4 Then
        web.Visible=True
        web.LoadUrl("http://www.ilcentesimo.com/sfoglia-il-volantino/")
    Else If Row = 5 Then
        web.Visible=True
        web.LoadUrl("https://www.lidl.it/contents/informazioni/i-nostri-volantini")
    Else If Row = 6 Then
        web.Visible=True
        web.LoadUrl("https://www.paghipoco.com/")
    Else If Row = 7 Then
        web.Visible=True
        web.LoadUrl ("https://www.famila.it/punti-vendita")
    Else If Row = 8 Then
        web.Visible=True
        web.LoadUrl("https://www.pennymarket.it/offerte/sfoglia-volantino")
    Else If Row = 9 Then
        web.Visible=True
        web.LoadUrl("https://www.e-coop.it/punti-vendita")
    Else If Row = 10 Then
        web.Visible=True
        web.LoadUrl("https://www.esselunga.it/cms/promozioni/volantini.html")
    Else If Row = 11 Then
        web.Visible=True
        web.LoadUrl("https://www.auchan.it/it-IT-it/Custom/Organa/PuntiVendita.aspx")
    Else If Row = 12 Then
        web.Visible=True
        web.LoadUrl("https://www.aeo.it/punti-vendita")
    Else If Row = 13 Then
        web.Visible=True
        web.LoadUrl("https://www.mdwebstore.it/")
    Else If Row = 14 Then
        web.Visible=True
        web.LoadUrl ("https://www.simplymarket.it/it-IT-it/Custom/Organa/PuntiVendita.aspx")
    Else If Row = 15 Then
        web.Visible=True
        web.LoadUrl("https://www.carrefour.it/volantini/")
    
        
    End If
End Sub
Sub timer1_Tick
    'web.Visible=True
    'pk1.Visible=True
    imgsplash.Visible=False
    timer1.Enabled=False
End Sub
Private Sub Page1_Resize(Width As Int, Height As Int)
    
End Sub

Private Sub Application_Background
    
End Sub
Sub btnaggiungi_Click
    
    Dim items As List = TableView1.GetItems(0)
    Dim tc As TableCell 'create a new item
    tc.InitializeSingleLine(txtordine.Text)
    items.InsertAt(0, tc)
    TableView1.ReloadSection(0)
    txtordine.Text=""
    
    
End Sub
 
Sub TableView1_SelectedChanged (SectionIndex As Int, Cell As TableCell)
    Dim items As List = TableView1.GetItems(0)
    TableView1.ReloadSection(0)
    items.RemoveAt(0)
End Sub
 
Top