ListView – Fyne Golang GUI Tutorial 55
ListView – Fyne Golang GUI Tutorial 55
We are using listView everywhere.
contact list, file list, website list etc
Fyne ListView tutorial is here for you.
Component of fyne listview
There are 3 main component of fyne listview.
1.Item count
Let suppose my list consist of 30 contacts number. I want to display their name and phone number in my listview.
2.items/ widget
Now I have to decide my widget. How I want to display my data to user. In a label or card ?
3.update data in widgets
I will setup listview to get the data and update data from the source.
OnSelected function in fyne listview
What function I want to perform, when the listview item is clicked/selected
OnUnselected function in fyne listview
And onUnselected is the opposite of onSelected. It will execute the function when a user unselect an item.
package main // import fyne import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/app" "fyne.io/fyne/v2/widget" ) func main() { a := app.New() // window and title w := a.NewWindow("List View") // resize w.Resize(fyne.NewSize(400, 400)) // list View // 3 arguments // item count, 3 itmes in list // widget, I want to use label widget // update data of widget list := widget.NewList( // lets change item count from 3 to 30 func() int { return 30 }, // my list contain 3 items func() fyne.CanvasObject { return widget.NewLabel("I want to use label") }, // last one func(lii widget.ListItemID, co fyne.CanvasObject) { // update data of widget co.(*widget.Label).SetText("Here is my text") }, ) // setup data on screen w.SetContent(list) w.ShowAndRun() }[easy_media_download url=”http://blogvali.com/wp-content/uploads/fyne-golang-downloads/main55.go” text=”Download Code” color=”red_darker”]