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.



<div>package main</div>
<div>// import fyne</div>
<div>import (</div>
<div>    ""</div>
<div>    ""</div>
<div>    ""</div>
<div>func main() {</div>
<div>    a := app.New()</div>
<div>    // window and title</div>
<div>    w := a.NewWindow("List View")</div>
<div>    // resize</div>
<div>    w.Resize(fyne.NewSize(400, 400))</div>
<div>    // list View</div>
<div>    // 3 arguments</div>
<div>    // item count, 3 itmes in list</div>
<div>    // widget, I want to use label widget</div>
<div>    // update data of widget</div>
<div>    list := widget.NewList(</div>
<div>        // lets change item count from 3 to 30</div>
<div>        func() int { return 30 }, // my list contain 3 items</div>
<div>        func() fyne.CanvasObject { return widget.NewLabel("I want to use label") },</div>
<div>        // last one</div>
<div>        func(lii widget.ListItemID, co fyne.CanvasObject) {</div>
<div>            // update data of widget</div>
<div>            co.(*widget.Label).SetText("Here is my text")</div>
<div>        },</div>
<div>    )</div>
<div>    // setup data on screen</div>
<div>    w.SetContent(list)</div>
<div>    w.ShowAndRun()</div>

Fyne Golang GUI Course

Tony BB

TonyBB is a Coach , marketer, hypnotist and a founder of RSKVF Production who specializes in providing simple, affordable, and easy to use solutions for Life.

Click Here to Leave a Comment Below 0 comments

Leave a Reply: