MainActivity類,在這段代碼中是否有任何錯誤?嘗試了很多方法,但仍然沒有工作我的Android TextView不可見
@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);
}
似乎可以得到我的選項菜單Convert_Currency工作?
<?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>
我menu.xml文件的全是代碼,更新的IT
所以基本上,當我按下菜單上的我的「轉換」按鈕,它該做的Convert_Currency – Thibaut
你重寫以下@覆蓋公共布爾onCreateOptionsMenu(菜單菜單){MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu,菜單);返回true; } –
是的,我做了@Override public boolean onCreateOptionsMenu(菜單菜單){ super.onCreateOptionsMenu(menu); this.myMenu =菜單; getMenuInflater()。inflate(R.menu.menu,menu); 返回true; } – Thibaut