两个完全相同的应用程序,但一个有效,另一个无效
Two exact same apps, but one works, the other one doesn´t
我有一个演示应用程序——我在其中弄清楚如何为我的真实应用程序和真实应用程序编写代码。
我希望在特定条件下将演示中称为 deck
的 ImageView
和真实应用程序中称为 deck1
的 deck1
替换为不同的可绘制对象。
在这两个应用程序中,这些条件都已满足,但在我的演示应用程序中,图像发生了变化,而在我的真实应用程序中却没有。同样在这两个应用程序中,完全相同的可绘制对象在我的可绘制文件中(是的,在两个应用程序文件夹中)。
代码演示应用程序:
deck = b.findViewById(R.id.imageView);
deck.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String standardWert= "Radler";
Bundle karteAusgewähltFinal = getArguments();
final String radlerWert = karteAusgewähltFinal.getString("2");
if (radlerWert == standardWert) {
deck.setBackgroundResource(R.drawable.radler_klein_level_1);}
else {
};}
}
);
return b;
}
}
和真正的应用程序:
deck1 = v.findViewById(R.id.deck_karte_1);
deck1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String wertIfCardIsChoosed = "Radler";
Bundle karteAusgewähltFinal = getArguments();
final String radlerWert = karteAusgewähltFinal.getString("2");
if (radlerWert == wertIfCardIsChoosed) {
deck1.setBackgroundResource(R.drawable.radler_klein_level_1);}
else {
};}
});
return v;
}
}
我的调试器也显示满足条件
我不知道这些应用程序之间有什么区别,也许你能找到原因,我会很高兴,因为我在过去的 5 个小时里一直在努力弄清楚这个问题。
编辑:XML 文件真实应用程序:
<ImageView
android:id="@+id/deck_karte_1"
android:layout_width="102dp"
android:layout_height="102dp"
android:clickable="true"
android:adjustViewBounds="true"
app:layout_constraintBottom_toBottomOf="@+id/deck_karte_1_hintergund"
app:layout_constraintEnd_toEndOf="@+id/deck_karte_1_hintergund"
app:layout_constraintStart_toStartOf="@+id/deck_karte_1_hintergund"
app:layout_constraintTop_toTopOf="@+id/deck_karte_1_hintergund"
app:srcCompat="@drawable/buttondeckcardclick" />
XML 文件演示应用程序:
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="358dp"
android:background="@drawable/deck_karten_hintergrund"
android:clickable="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
我发现你的 ImageView 在实际应用中有 srcCompat 属性。
我假设你的 ImageView 的背景会被你的 ImageView 的前景隐藏。
所以我建议你去掉srcCompat后再测试属性。
<ImageView
android:id="@+id/deck_karte_1"
android:layout_width="102dp"
android:layout_height="102dp"
android:clickable="true"
android:adjustViewBounds="true"
app:layout_constraintBottom_toBottomOf="@+id/deck_karte_1_hintergund"
app:layout_constraintEnd_toEndOf="@+id/deck_karte_1_hintergund"
app:layout_constraintStart_toStartOf="@+id/deck_karte_1_hintergund"
app:layout_constraintTop_toTopOf="@+id/deck_karte_1_hintergund" />
我有一个演示应用程序——我在其中弄清楚如何为我的真实应用程序和真实应用程序编写代码。
我希望在特定条件下将演示中称为 deck
的 ImageView
和真实应用程序中称为 deck1
的 deck1
替换为不同的可绘制对象。
在这两个应用程序中,这些条件都已满足,但在我的演示应用程序中,图像发生了变化,而在我的真实应用程序中却没有。同样在这两个应用程序中,完全相同的可绘制对象在我的可绘制文件中(是的,在两个应用程序文件夹中)。
代码演示应用程序:
deck = b.findViewById(R.id.imageView);
deck.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String standardWert= "Radler";
Bundle karteAusgewähltFinal = getArguments();
final String radlerWert = karteAusgewähltFinal.getString("2");
if (radlerWert == standardWert) {
deck.setBackgroundResource(R.drawable.radler_klein_level_1);}
else {
};}
}
);
return b;
}
}
和真正的应用程序:
deck1 = v.findViewById(R.id.deck_karte_1);
deck1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String wertIfCardIsChoosed = "Radler";
Bundle karteAusgewähltFinal = getArguments();
final String radlerWert = karteAusgewähltFinal.getString("2");
if (radlerWert == wertIfCardIsChoosed) {
deck1.setBackgroundResource(R.drawable.radler_klein_level_1);}
else {
};}
});
return v;
}
}
我的调试器也显示满足条件
我不知道这些应用程序之间有什么区别,也许你能找到原因,我会很高兴,因为我在过去的 5 个小时里一直在努力弄清楚这个问题。
编辑:XML 文件真实应用程序:
<ImageView
android:id="@+id/deck_karte_1"
android:layout_width="102dp"
android:layout_height="102dp"
android:clickable="true"
android:adjustViewBounds="true"
app:layout_constraintBottom_toBottomOf="@+id/deck_karte_1_hintergund"
app:layout_constraintEnd_toEndOf="@+id/deck_karte_1_hintergund"
app:layout_constraintStart_toStartOf="@+id/deck_karte_1_hintergund"
app:layout_constraintTop_toTopOf="@+id/deck_karte_1_hintergund"
app:srcCompat="@drawable/buttondeckcardclick" />
XML 文件演示应用程序:
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="358dp"
android:background="@drawable/deck_karten_hintergrund"
android:clickable="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
我发现你的 ImageView 在实际应用中有 srcCompat 属性。
我假设你的 ImageView 的背景会被你的 ImageView 的前景隐藏。
所以我建议你去掉srcCompat后再测试属性。
<ImageView
android:id="@+id/deck_karte_1"
android:layout_width="102dp"
android:layout_height="102dp"
android:clickable="true"
android:adjustViewBounds="true"
app:layout_constraintBottom_toBottomOf="@+id/deck_karte_1_hintergund"
app:layout_constraintEnd_toEndOf="@+id/deck_karte_1_hintergund"
app:layout_constraintStart_toStartOf="@+id/deck_karte_1_hintergund"
app:layout_constraintTop_toTopOf="@+id/deck_karte_1_hintergund" />