当有很多孩子时如何从特定的孩子按钮获取文本

问题描述

我有6个按钮。每个都有不同的文本。按下任意按钮将调用一种相同的方法,该方法可更改文本并更改它们之间的按钮位置。按下按钮时,我无法弄清楚如何从特定按钮获取文本。我只能返回随机按钮文本或全部返回。像这样:

<a> @ <b>

所以我需要任何建议。谢谢。

buttons

解决方法

您可以将pub struct Thing { value: i32,} impl Thing { pub fn new(value: i32) -> Thing { Thing { value,} } fn in_thread(&self) { println!("in thread"); // do things that block the thread } pub fn spawn_thread(&self) { std::thread::spawn(move || { self.in_thread(); // problem occurs here }); } } 添加到int之类的按钮单击功能中,然后根据ReadFromButton(int i)

在onclickevent中统一给按钮编号。

赞:

public Text[] buttontexts

但是我相信还有更多的方法可以做到这一点。