【发布时间】:2015-08-10 18:41:32
【问题描述】:
我的项目中有以下代码
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
如何修复此代码?有没有可以让图片出现顺序的功能?
【问题讨论】:
-
你必须使用一个count变量来增加int的值。就像 int n; n++;心脏图像[n]
-
它不是 C 并且 heartimage 不是指针 ...
-
@Deepak Goyal 你的意思是像索引的功能?
-
@Ricci 是的,就像索引的功能。