Auto.js UI 列表控件使用方法 数字题计算

"ui";
ui.layout(
    <vertical>
        <horizontal>
            <button id="设置"text="设置"/>
            <input id="数字"text="100"w="100dp"/>
            <text text="内加减法"textSize="25"/>
        </horizontal>
        <list id="列表">
            <horizontal>
                <text id="名字"text="{{题}}="w="auto"/>
                <input id="输入框"w="100"/>
                <text id="判断"/>
            </horizontal>
        </list>
        <button id="提交"text="提交"/>
    </vertical>
);
设置题()
ui.设置.click(() => {
    设置题()
})
function 设置题(){
    结果 = []
    let 数字 = ui.数字.text() - 0
    let items = []
    for (let i = 0; i < 10; i++) {
        let a = random(0, 1)
        let b, c, d
        if (a == 0) {
            b = random(0, 数字)
            c = random(0, 数字 - b)
            d = "+"
            结果.push(b + c)
        } else {
            b = random(0, 数字)
            c = random(0, b)
            d = "-"
            结果.push(b - c)
        }
        if (b > 0) {
            items.push({
                "题": b + d + c,
            })
        } else {
            i--
        }
    }
    ui.列表.setDataSource(items);
}
ui.提交.click(() => {
    for (var i = 0; i < ui.列表.getChildCount(); i++) {
        let jg = ui.列表.getChildAt(i).getChildAt(1);
        let pd = ui.列表.getChildAt(i).getChildAt(2);
        if (jg.getText() == 结果[i]) {
            pd.setText("√")
        } else {
            pd.setText("×")
        }
    }
})

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值