0

我的申请有问题。问题是我无法在活动之间从一个选项卡切换到另一个选项卡。这是我的代码:

     public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
            String n = tab.getText().toString();
            Toast.makeText(getApplicationContext(), "You have selected: " + n, Toast.LENGTH_LONG).show();
            if (n =="Converter") {
                startActivity(new Intent ("com.example.currencyconverter.MainActivity"));
                }
            if (n =="Currencies") {
                startActivity(new Intent ("com.example.currencyconverter.FirstActivity"));  
            if (n=="News") {
                startActivity(new Intent ("com.example.currencyconverter.FirstActivity"));  
                  }
                }

        }

我的应用程序崩溃了。问题是什么?任何帮助将不胜感激。

4

2 回答 2

2

Java 不像 C# 那样比较字符串

在 Java 中是

if(n.equals("Converter"))
{   /// do something }
于 2013-06-24T21:18:59.817 回答
1

更改您的字符串比较以使用等于和您的

startActivity(new Intent ("com.example.currencyconverter.MainActivity"));

startActivity(new Intent (this, MainActivity.class));

于 2013-06-24T21:19:19.080 回答