【发布时间】:2014-12-18 20:07:29
【问题描述】:
您好,几个月前我发布了我的应用程序,一切都运行良好,并且在某种程度上仍然如此。在运行低于 android 5 的设备上一切正常。但是我今天在 5 台设备上进行了测试,我的 if 语句不起作用。例如,它将每个答案标记为不正确,但在较低的设备上,正确的不正确答案正在按预期工作。我知道我的代码可以工作,但我不知道为什么它不能在 android 5 上工作。我唯一能想到的是我在清单上遗漏了一些东西。
编辑:工作答案允许
之间的兼容性 button.setOnClickListener(new OnClickListener(){
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override
public void onClick(View arg0) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
if (Word1.getDrawable().getConstantState().equals(Word1.getResources().getDrawable( R.drawable.img1).getConstantState())}}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (Word1.getDrawable().getConstantState().equals(Word1.getContext().getDrawable( R.drawable.img1).getConstantState())}} });
【问题讨论】:
-
您能否发布一个无效的 IF 语句示例?
-
我添加了一个 if 语句。但我知道 if 语句有效,但由于某种原因在 android 5 上无效。如果需要,我有一个相同代码的视频
-
你可以尝试使用
.equals而不是==比较对象 -
对棉花糖不起作用 :(
标签: android xml if-statement android-manifest