Reputation: 19
MainActivity class, is there any error in this code? Tried many methods but still doesnt work
@Override
public boolean onOptionsItemSelected(MenuItem item){
double CurrencyRate;
double a;
double b;
switch(item.getItemId()) {
case R.id.action_Custom:
Intent intent = new Intent(this,CustomXchangeRate.class);
this.startActivity(intent);
break;
case R.id.Convert_Currency:
if (CurrencyTV.toString()=="AUD"){
CurrencyRate=0.944;
a=Double.parseDouble(FrTV.getText().toString());
b=CurrencyRate*a;
String c =Double.toString(b);
SgdTV.setText(c);
}
Can seem to get my option menu Convert_Currency working?
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:title="Convert"
android:id="@+id/Convert_Currency"
app:showAsAction="always"
/>
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
app:showAsAction="never"
android:title="Settings"/>
<item
android:id="@+id/action_Custom"
android:orderInCategory="100"
app:showAsAction="never"
android:title="Add custom Rates"/>
<item
android:id="@+id/action_Default"
android:orderInCategory="100"
app:showAsAction="never"
android:title="Show Default Rates"/>
</menu>
My menu.xml full codes of it, Updated it
Upvotes: 0
Views: 64
Reputation: 17535
please try to convert your textview's text value instead of TextView.
if (CurrencyTV.getText().toString().equals("AUD"))// Change here
Upvotes: 1
Reputation: 2577
Replace your if condition by this.
It will worked
if (CurrencyTV.getText().toString().equalsIgnoreCase("AUD"))
Upvotes: 2