我的项目中有以下代码
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
如何修复此代码?是否有一个功能可以使图像顺序显示?
答案 0 :(得分:2)
然后是lifesimage.setImageResource(heartimage [index]);