B4J Question ListView Error for reader item name

Roberto P.

Well-Known Member
Licensed User
Longtime User
I used a ListView component with a simple list.
I need to read the item on which click event was generated.

I used the following method:

B4X:
Sub mCtrlLVMenu_MouseClicked (EventData As MouseEvent)

    Log("ClickCount " & EventData.ClickCount)
   
    Try
        Dim jo As JavaObject     =    EventData
    Dim code As String         =     jo.RunMethod("getCode", Null)
    Catch
        Log(LastException)
    End Try
   

    Log("menu " & code)
   
End Sub

but by mistake:
(RuntimeException) java.lang.RuntimeException: Method: getCode not found in: javafx.scene.input.MouseEvent


Where am I wrong? How do I simply read the voice where the click was clicked?

Thank you
 

Roberto P.

Well-Known Member
Licensed User
Longtime User
You should handle the SelectedIndexChanged event.

ok, if I understand well there is no way to read the voice when i click, but do I have to read and save the selected item to use when a user clicks the click?
thank you
 
Upvote 0

Roberto P.

Well-Known Member
Licensed User
Longtime User
I look the same behavior as the Android list view, which with the click is passed ItemPosition and voice.
So, I'd like to intercept the string when double click is pressed
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Think this example does what you want
B4X:
Sub Process_Globals
	Private fx As JFX
	Private MainForm As Form
	Dim li As ListView
End Sub

Sub AppStart (Form1 As Form, Args() As String)
	MainForm = Form1
	'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
	MainForm.Show
	li.Initialize("li")
	For a = 0 To 10
		li.Items.Add("Item "&a)
	Next
	MainForm.RootPane.AddNode(li,10,10,200,300)
	
End Sub
Sub li_MouseClicked (EventData As MouseEvent)
	If EventData.ClickCount = 2 Then
		Log(li.SelectedItem)
	End If
End Sub
'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
	Return True
End Sub
 
Upvote 0
Top