我尝试了数十种不同的组合,但我不知道为什么这行不通 - 其中的逻辑是完全有道理的。
我正在传递来自先前 Activity 的包,该包已将微调器中的值存储到字符串中。然后,我读取该字符串,如果它与我指定的内容等效,则执行该字符串。
我已将字符串直接打印到 TextView,只是为了确保获得预期的结果,而且确实如此 - 但它仍然无法注册。
TextView tv;
Bundle extras = getIntent().getExtras();
tv = (TextView) findViewById(R.id.textView2);
tv.append(extras.getString("pageNumber"));
tv = (TextView) findViewById(R.id.textView3);
int base = Integer.parseInt(extras.getString("pageNumber")) * 70;
tv.append(Integer.toString(base));
/* Here is where I'm editing */
tv = (TextView) findViewById(R.id.textView4);
String plat = extras.getString("platform");
if (plat == "Wordpress") tv.append("900");
我的微调器数组在 strings.xml 中定义,如下所示:
<string-array name="platform_array">
<item>None</item>
<item>Joomla</item>
<item>Wordpress</item>
<item>Drupal</item>
</string-array>
最佳答案
==
是比较两个对象,equals
或 equalsIgnoreCase
是比较两个对象的值。
关于java - 将 bundle 中的字符串与本地值进行比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8967270/