customDialog, panel & ListView

Status
Not open for further replies.

Fabrice La

Active Member
Licensed User
Longtime User
Hi,

I try to use customDialog, panel & ListView to display choose for the user. The list is in file "Devise.txt". When the user click the label the panel opened but nothing in it ??
Can you tell me why ?

Thanks


Sub Globals
Dim lblDevise As Label
Dim lv As ListView
Dim pnl As Panel
Dim cd As CustomDialog
....
end sub

Sub Activity_Create(FirstTime As Boolean)
....
lv.Initialize("lv")
pnl.Initialize("pnl")
TR.Initialize(File.OpenInput(File.DirDefaultExternal, "Devise.txt"))
Dim line As String
Do While line <> Null
line = TR.ReadLine
lv.AddSingleLine(line)
Loop
TR.Close
End Sub

Sub lblDevise_Click
cd.AddView(pnl,0,0, 77%x, 60%y )
ret = cd.Show("Devises", "OK", "Cancel","" , Null)
End Sub
Sub lv_ItemClick (Position As Int, Value As Object)
ToastMessageShow(Position, True)
ToastMessageShow(Value, True)
End Sub
 

kickaha

Well-Known Member
Licensed User
Longtime User
You do not appear to be adding your ListView (lv) to the Panel (pnl) anywhere in that code.
 
Upvote 0

Fabrice La

Active Member
Licensed User
Longtime User
Oupss !
I forgot a line in pasting the code ...

Sub Globals
Dim lblDevise As Label
Dim lv As ListView
Dim pnl As Panel
Dim cd As CustomDialog
....
end sub

Sub Activity_Create(FirstTime As Boolean)
....
lv.Initialize("lv")
pnl.Initialize("pnl")
TR.Initialize(File.OpenInput(File.DirDefaultExtern al, "Devise.txt"))
Dim line As String
Do While line <> Null
line = TR.ReadLine
lv.AddSingleLine(line)
Loop
TR.Close
pnl.AddView(lv, 0, 0, 120dip, 250dip)
End Sub

Sub lblDevise_Click
cd.AddView(pnl,0,0, 77%x, 60%y )
ret = cd.Show("Devises", "OK", "Cancel","" , Null)
End Sub
Sub lv_ItemClick (Position As Int, Value As Object)
ToastMessageShow(Position, True)
ToastMessageShow(Value, True)
End Sub
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Try to move this line:
B4X:
cd.AddView(pnl,0,0, 77%x, 60%y )
from the Sub lblDevise_Click routine to the Activity_Create routine.
When you post code you should put it between Code tags.
The # button, or put
B4X:
 before the code and
at the end of the code. It makes the code better readable.
Another way to get an answer, the best way for me, is to post the project as a zip file or at least a smaller project that shows the problem. In this case we can test the project in the same conditions as you do and give you the best advice.

Best regards.
 
Upvote 0

admac231

Active Member
Licensed User
Longtime User
I realise this may not be very helpful but the code works fine for me. I had to add a few bits of code to show labels and things but other than that it's fine. Are you sure there's data in Devise.txt?

Anyway, here's the code I used:
B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
Dim lblDevise As Label
Dim lv As ListView
Dim pnl As Panel
Dim cd As CustomDialog
Dim tr As TextReader
Dim ret As Int
End Sub

Sub Activity_Create(FirstTime As Boolean)

lblDevise.Initialize("lblDevise")
lblDevise.Text = "Touch"
Activity.AddView(lblDevise,0,0,100%x,50dip)
lv.Initialize("lv")

pnl.Initialize("pnl")
tr.Initialize(File.OpenInput(File.DirAssets, "test.txt"))
Dim line As String
Do While line <> Null
line = tr.ReadLine
lv.AddSingleLine(line)
Loop
tr.Close
pnl.AddView(lv, 0, 0, 120dip, 250dip)
End Sub

Sub lblDevise_Click
cd.AddView(pnl,0,0, 77%x, 60%y )
ret = cd.Show("Devises", "OK", "Cancel","" , Null)
End Sub
Sub lv_ItemClick (Position As Int, Value As Object)
ToastMessageShow(Position, True)
ToastMessageShow(Value, True)
End Sub

f1hM0.png

ldD5N.png
 
Upvote 0

Steve Kwok

Member
Licensed User
ListView in CustomLayoutDialog instead of CustomDialog

B4X:
Sub Globals

    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private lblDevice As Label
    Private cld As CustomLayoutDialog   
    Private ListView1 As ListView
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")       
    lblDevice.Initialize("lblDevice")
    lblDevice.TextSize = 48
    lblDevice.TextColor = Colors.Blue
    lblDevice.Text = "Touch Lv"
    Activity.Title = "ListView in Dialog"
    Activity.AddView(lblDevice,10dip,10dip,80%x,100dip)
    Activity.AddMenuItem("next", "next")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub next_click
    StartActivity(ClvDialog)
End Sub

Sub lblDevice_Click
    Dim sf As Object = cld.ShowAsync("Devices Two", "Yes", "Cancel", "No", Null, False)
    cld.SetSize(80%x, 80%y)
    Wait For (sf) Dialog_Ready(DialogPanel As Panel)
    DialogPanel.LoadLayout("lvdialog.bal")
    Dim gd As GradientDrawable
    gd.Initialize("TR_BL", Array As Int(Colors.Blue, Colors.Black))
    DialogPanel.Background = gd
    Dim lstdata As List = gettextFromFile
    Dim i As Int = 0
    For i = 0 To lstdata.Size -1
        ListView1.AddSingleLine2(lstdata.Get(i), i)
    Next
    Wait For (sf) Dialog_Result(Result As Int)
    If Result = DialogResponse.POSITIVE Then
        '...
    End If
End Sub

Sub ListView1_ItemClick (Position As Int, Value As Object)
    Dim msg As String = $"Position: ${Position}; Value: ${Value}"$
    ToastMessageShow(msg, True)
End Sub

Private Sub gettextFromFile() As List
    Dim lst As List : lst.initialize
    If File.Exists(File.DirAssets, "test.txt") = False Then
        Return lst
    End If
    Dim tr As TextReader
    tr.Initialize(File.OpenInput(File.DirAssets, "test.txt"))
    Dim line As String
    Do While line <> Null
        line = tr.ReadLine
        If line <> Null Then
            lst.Add(line)
        End If
    Loop
    tr.Close
    Return lst
End Sub

Screenshot-2019-10-31-11-10-34.png


 

Attachments

  • ListViewInDialog.zip
    22.7 KB · Views: 273
Upvote 0
Status
Not open for further replies.
Top