嘿,我試圖解決這個難題我如何為我擁有的每個單獨的按鈕設定 func ?所以它對我所有的 3 個按鈕做同樣的事情
應該可以通過使用 onselected 我只是想不出如何正確處理它。是的,我確實閱讀了 Fyne 的檔案;=)
我知道它不是實際的按鈕,但它們應該具有與按鈕相同的選項,只需使用 onselected
fyne 檔案關于 widget.list https://developer.fyne.io/api/v2.0/widget/list.html
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
func main() {
a := app.New()
a.Settings().SetTheme(theme.DarkTheme())
W := a.NewWindow("Application-OutSight")
W.Resize(fyne.NewSize(640, 460))
menuBar := []strings{"Home","App-Status", "Exit"}
listView := widget.NewList(func() int {
return len(menuBar)
}, func() fyne.CanvasObject {
return widget.NewLabel("template")
}, func(id widget.ListItemID, o fyne.CanvasObject) {
o.(*widget.Label).SetText = (menuBar[id])
})
contenttext := widget.NewLabel("Welcome to this App")
//what i want is this, but dont know how to get right
listView.OnSelected[0] = func(id widget.ListItemID) { //button 0
}
listView.OnSelected[1] = func(id widget.ListItemID) { //button 1
}
listView.OnSelected[2] = func(id widget.ListItemID) { //buttton2
}
split := (container.NewHSplit(
listView,
container.NewMax(contenttext),
))
split.Offset = 0.2
W.SetContent(split)
W.ShowAndRun()
}
uj5u.com熱心網友回復:
widget.List.OnSelected 的引數widget.ListItemID是一個 int。
您可以使用此 id 來呼叫不同專案的函式
listView.OnSelected = func(id widget.ListItemID) {
switch id {
case 0:
//call button/list-item 0 func here
case 1:
//call button/list-item 1 func here
case 2:
//call button/list-item 2 func here
default:
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/511675.html
標籤:去用户界面法恩
