Reputation: 153
I have an issue in my application. The issue is that I cannot switch between activities from one tab to another. Here is my code:
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"));
}
}
}
My app is crashing. What is the issue? Any help would be greatly appreciated.
Upvotes: 0
Views: 105
Reputation: 2348
Change your String comparisons to use equals and your
startActivity(new Intent ("com.example.currencyconverter.MainActivity"));
to
startActivity(new Intent (this, MainActivity.class));
Upvotes: 1
Reputation: 4001
Java does not compare string like C#
In Java it is
if(n.equals("Converter"))
{ /// do something }
Upvotes: 2