java - 将 bundle 中的字符串与本地值进行比较

标签 java android bundle

我尝试了数十种不同的组合,但我不知道为什么这行不通 - 其中的逻辑是完全有道理的。

我正在传递来自先前 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>

最佳答案

== 是比较两个对象,equalsequalsIgnoreCase 是比较两个对象的值。

关于java - 将 bundle 中的字符串与本地值进行比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8967270/

相关文章:

java - Android:movie.draw 上 0x00000000(代码=1)处的致命信号 11 (SIGSEGV)

java - 为什么我的 RxJava Observable 除非阻塞,否则不会发出或完成?

android - 如何在 n 秒延迟后动态显示进度对话框按钮

c++ - 如何在 Qt 的 Mac 应用程序包中 bundle dylib?

php - FosuserBundle(路径 "fos_user.from_email.address"不能包含空值,但为空。)

Ruby on Rails - 列出所有第 3 方库详细信息和许可

java - 解析此消息

java - 这个函数的T(n)怎么写?

android - 具有 singleTask 启动模式的 Activity 及其在后台堆栈中的位置

java - Android RecyclerView 不回收项目