1
我有一個比較字符串的問題:我得到string.xml中的「激活」的字符串值。當我與具有相同值的字符串值進行比較,結果總是假的(在string.xml激活=測試)getString()string.xml比較
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">MyNameApp</string>
<string name="activation">test</string>
</resources>
public class CheckGenuine {
public static String cod;
public static String app;
public static Boolean chk(Context ctx) {
Boolean ret;
cod = ctx.getString(R.string.activation);
app = ctx.getString(R.string.app_name);
if (cod == "test") {
Toast.makeText(ctx, "True cod = " + cod, Toast.LENGTH_LONG).show();
ret = true;}
else {
Toast.makeText(ctx, "False cod = " + cod, Toast.LENGTH_LONG).show();
ret = false;}
// *** why ret is always false and Toast shows "False cod = test" ????????????????
return ret;
}
}
謝謝!我瘋了:-) – user1549319 2012-07-24 17:21:15