Android Question ListView Get Line1 and Line2

Don Roberts

Member
Licensed User
I am using the listview for 2 lines as:

B4X:
BulletPenList.AddTwoLines(".223 Remington","55 gr Winchester Soft Point  0.430")

I am reading the click event as:
B4X:
Sub BulletPenList_ItemClick (Position As Int, Value As Object)
'first line of text
BulletPenCname.Text=BulletPenList.GetItem(Position)
End Sub

The listview was built in the designer and dimmed and works for getting the first line.
How do I go about reading the second line?
 

eurojam

Well-Known Member
Licensed User
Longtime User
you can use a Map (collection) to get the second line:
B4X:
BulletPenList.AddTwoLines(".223 Remington","55 gr Winchester Soft Point  0.430")
aMap.put(".223 Remington","55 gr Winchester Soft Point  0.430")
and then
B4X:
Sub BulletPenList_ItemClick (Position As Int, Value As Object)
  Log(Value) 'first line
  Log(aMap.Get(Value))  'second line
End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
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 lv 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")
    lv.Clear
    Dim m As Map
    m.Initialize
    m.Put("Line1","Bla bla bla")
    m.Put("Line2","ho ho ho")
    m.Put("Another string or whatever","Test")
    lv.AddTwoLines2(m.Get("Line1"),m.Get("Line2"),m)
    Dim m As Map
    m.Initialize
    m.Put("Line1","Hello World")
    m.Put("Line2","Most used words in Examples")
    m.Put("Another string or whatever","Test")
    lv.AddTwoLines2(m.Get("Line1"),m.Get("Line2"),m)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub lv_ItemClick (Position As Int, Value As Object)
    Dim m As Map = Value
    Log("Clicked item no "&Position)
    Log("Line1: "&m.Get("Line1"))
    Log("Line2: "&m.Get("Line2"))
   
End Sub
 

Attachments

  • lvitems.zip
    7.1 KB · Views: 177
Upvote 0

Don Roberts

Member
Licensed User
B4X:
BulletPenList.AddTwoLines(".223 Remington","55 gr Winchester Soft Point  0.430 Rifle")
        MeplatBulletName(1) ="55 gr Winchester Soft Point  0.430 Rifle"
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 lv 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")
    lv.Clear
    Dim m As Map
    m.Initialize
    m.Put("Line1","Bla bla bla")
    m.Put("Line2","ho ho ho")
    m.Put("Another string or whatever","Test")
    lv.AddTwoLines2(m.Get("Line1"),m.Get("Line2"),m)
    Dim m As Map
    m.Initialize
    m.Put("Line1","Hello World")
    m.Put("Line2","Most used words in Examples")
    m.Put("Another string or whatever","Test")
    lv.AddTwoLines2(m.Get("Line1"),m.Get("Line2"),m)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub lv_ItemClick (Position As Int, Value As Object)
    Dim m As Map = Value
    Log("Clicked item no "&Position)
    Log("Line1: "&m.Get("Line1"))
    Log("Line2: "&m.Get("Line2"))
  
End Sub

aah OK I thought I was missing something in the calls.
I just went ahead and declared a global array as:
B4X:
Sub Globals
Dim MeplatBulletName(500)
End Sub

BulletPenList.AddTwoLines(".223 Remington","55 gr Winchester Soft Point  0.430 Rifle")
MeplatBulletName(1) ="55 gr Winchester Soft Point  0.430 Rifle"
BulletPenList.AddTwoLines(".223 Remington","55 gr Winchester Ballistic Silvertip 0.398 Rifle")
MeplatBulletName(2) ="55 gr Winchester Ballistic Silvertip 0.398 Rifle"
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
The listview was built in the designer and dimmed and works for getting the first line.
How do I go about reading the second line?

Remember you can use the ListView.AddTwoLines2 Method to stipulate the return value ..

B4X:
BulletPenList.AddTwoLines2(".223 Remington","55 gr Winchester Soft Point  0.430","55 gr Winchester Soft Point  0.430")

B4X:
Sub BulletPenList_ItemClick (Position As Int, Value As Object)
BulletPenCname.Text=Value
End Sub

*** Edit .. Ive just notice @DonManfred has suggested same ....
And Iv'e just realized @Don Roberts wants to read both lines ... so IGnore !
 
Last edited:
Upvote 0
Top