按顺序查找并获取 2 个点击按钮的 id

约翰·史密斯

我正在制作一个点击相同的 2 张重复图片的程序。如果用户在点击第一张图片后点击了错误的图片,则会出现负值。如果两张图片相同,我将这些按钮设置为可点击(假)。但我的问题是,当第二张图片与第一张图片不同时,我想将 clickable(true) 设置为第二张图片以及第一张图片,但我不知道如何获取第一个点击按钮的 id。

我有 16 个按钮,在这里,我发布了 button1,其他按钮类似。我的代码是.....

 Collections.shuffle(buttonResources);
        for(int i = 0; i < buttonResources.size(); i++)
        {
            ImageButton bt = findViewById(buttonResources.get(i));
            buttons.add(bt);
            bt.setBackgroundResource(pics.get(i/2));
            bt.setTag(pics.get(i/2));
            aaa = pics.get(i/2);
            bt.setOnClickListener(this);
            bt.setClickable(false);
        }

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                AlphaAnimation alphaAnimation0 = new AlphaAnimation(1,0);
                alphaAnimation0.setDuration(200);
                alphaAnimation0.setFillAfter(true);

                for(int i = 0; i < buttonResources.size(); i++)
                {
                    ImageButton bt = findViewById(buttonResources.get(i));
                    buttons.add(bt);
                    bt.startAnimation(alphaAnimation0);

                    bt.setClickable(true);
                }

            }
        }, 5000);




        }

    @Override
    public void onClick(final View v1) {
        switch (v1.getId()) {
            case R.id.bt1:
                AlphaAnimation alphaAnimation1 = new AlphaAnimation(0, 1);
                alphaAnimation1.setDuration(300);
                alphaAnimation1.setFillAfter(true);
                bt1.startAnimation(alphaAnimation1);
                aaa = (int) bt1.getTag();
                bt1.setClickable(false);

                if(bbb==0){
                    bt1.setClickable(false);
                    bbb = aaa;
                }else if (bbb==aaa){
                    right++;
                    tvtext.setText("Right" + right + "wRONG" + wrong);
                    bbb=0;

                }else{
                    wrong++;
                    tvtext.setText("Right" + right + "wRONG" + wrong);
                    bbb=0;
                    AlphaAnimation alphaAnimation = new AlphaAnimation(1,0);
                    alphaAnimation.setDuration(600);
                    alphaAnimation.setFillAfter(true);
                    bt1.startAnimation(alphaAnimation);
                    bt1.setClickable(true);
                    }
                break;
法拉赫阿雷祖达尔

添加int bbbID=0;然后添加这些更改:

case R.id.bt1:
                AlphaAnimation alphaAnimation1 = new AlphaAnimation(0, 1);
                alphaAnimation1.setDuration(300);
                alphaAnimation1.setFillAfter(true);
                bt1.startAnimation(alphaAnimation1);
                aaa = (int) bt1.getTag();
                bt1.setClickable(false);

                if(bbb==0){
                    bt1.setClickable(false);
                    bbb = aaa;
                    bbbID = v1.getId();   //////change
                }else if (bbb==aaa){
                    right++;
                    tvtext.setText("Right" + right + "wRONG" + wrong);
                    bbb=0;
                    bbbID = 0;   //////change

                }else{
                    wrong++;
                    tvtext.setText("Right" + right + "wRONG" + wrong);
                    bbb=0;
                    AlphaAnimation alphaAnimation = new AlphaAnimation(1,0);
                    alphaAnimation.setDuration(600);
                    alphaAnimation.setFillAfter(true);
                    bt1.startAnimation(alphaAnimation);
                    bt1.setClickable(true);
                    for(int i=0;i<buttons.size();i++){   //////change
                       if(buttons.get(i).getId() == bbbID){   //////change
                           buttons.get(i).setClickable(true);   //////change
                       }
                    }
                    }
                break;

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

获取点击按钮的ID

来自分类Dev

获取点击按钮的ID

来自分类Dev

获取点击的按钮的ID的JavaScript

来自分类Dev

获取点击的图像按钮的ID

来自分类Dev

React获取点击按钮的ID

来自分类Dev

点击时按顺序递增ID名称

来自分类Dev

显示以下按钮点击2个元件

来自分类Dev

如何获得一个按钮的ID在点击的按钮?

来自分类Dev

在Kotlin中按ID查找按钮

来自分类Dev

如何从片段中按ID查找按钮

来自分类Dev

按 2 个 ID 分组的 SQL

来自分类Dev

在Rails中按顺序获取ID

来自分类Dev

JS:按特定顺序获取对象的 ID

来自分类Dev

用一个按钮改变数据内容,(根据按钮点击改变sql id)

来自分类Dev

获取被点击元素的ID

来自分类Dev

获取点击行的ID

来自分类Dev

获取被点击的 <li> 的 ID

来自分类Dev

如何从select2关闭按钮获取最近的ID?

来自分类Dev

单击时如何从Ionic 2中的按钮获取ID?

来自分类Dev

按2个ID字段返回“最近记录”组

来自分类Dev

按ID在链接上显示2个表

来自分类Dev

在SQL中按名称替换2个ID

来自分类Dev

查找猫鼬数组中存在2个id的位置

来自分类Dev

点击按钮获取IllegalStateException

来自分类Dev

按钮内的 HTML href(如 chrome 标签) 1 个按钮中有 2 个不同的点击功能

来自分类Dev

比较2个文本文件并获取内部ID

来自分类Dev

sql查询以基于2个ID获取记录

来自分类Dev

MySQL从2个表查询,获取ID值?

来自分类Dev

尝试使用Linq从2个表中获取ID的总价