我的项目中有以下代码

ImageView lifesimage, good;
TextView lifes1;

int gamelifes=6, gamehints=6, index=0;
int [] heartimage={R.drawable.lifessix,
                   R.drawable.lifesfive,
                   R.drawable.lifesfour,
                   R.drawable.lifesthree,
                   R.drawable.lifestwo,
                   R.drawable.lifesone,
                   R.drawable.lifesno,
                   };

    good=(ImageView)findViewById(R.id.youwin);

    lifesimage =(ImageView)findViewById(R.id.lifes);
    lifesimage.setImageResource(heartimage[0]);

    lifes1 =(TextView)findViewById(R.id.lifestext);
    lifes1.setTextColor(Color.RED);
    lifes1.setText(String.valueOf(gamelifes));


因此,如果答案正确或错误,则代码为

 if(you.equalsIgnoreCase(answer[index]))
            {
                good.setVisibility(View.VISIBLE);
            }
            else
            {
                heartimage++;
                gamelifes--;
                lifes1.setText(String.valueOf(gamelifes));
            }


但是我在heartimage++;上发现了一些错误,例如类型不匹配:无法从int []转换为int
如何解决此代码?有没有可以使图像顺序显示的功能?

最佳答案

您的代码中的“ heartimage”是一个整数数组,您正尝试向其添加1 ...无法正常工作。创建一个新的变量“ index”(或任何您想命名的变量),该变量将存储所需心形值的当前索引。

然后是lifesimage.setImageResource(heartimage [index]);

10-07 13:41
查看更多