HarmonyOS-统计十秒按钮点击次数

HUAWEI_Engineer
发布于 2021-11-2 13:58
浏览
0收藏
public class MainAbilitySlice extends AbilitySlice implements Component.ClickedListener {
    Text text;
    Button button ;
    @Override
    public void onStart(Intent intent) {

        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        //拿到Button Text按钮
        text = (Text)findComponentById(ResourceTable.Id_text);
        button = (Button)findComponentById(ResourceTable.Id_but1);
        //设置点击方法
        button.setClickedListener(this);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }


    boolean flag = true;
    long Starttime = 0;

    int conut = 0;

    @Override
    public void onClick(Component component) {
        conut++;
        if (flag){
            Starttime = System.currentTimeMillis();
            button.setText("请点击");
            flag = false;
        }else
            if ((System.currentTimeMillis()-Starttime)<=10000){
                text.setText(conut+"");
        }
        else {
            button.setText("结束");
            button.setClickable(false);
        }


    }
}


2.效果图
HarmonyOS-统计十秒按钮点击次数-鸿蒙开发者社区
HarmonyOS-统计十秒按钮点击次数-鸿蒙开发者社区

标签
2
收藏
回复
举报
回复
    相关推荐