2013-01-01 23 views
1

我在Android中製作計算器。Java字符串中的cuberoot符號

爲此,我使用各種按鈕,其中三個用於PI,平方根和立方根的符號。

現在,當我測試這個在NetBeans的一個簡單的代碼:

public class Test { 
    public static void main(String[] args) { 
     System.out.println("\u03C0"); 
     System.out.println("\u221A"); 
     System.out.println("\u221B"); 
    } 
} 

我得到預期的輸出:

運行:

π

然而,當我做類似的顯示的Android發展使用eclipse:

public static String[] button_text = new String[]{ 
    "^",  "ln(",  "log(",  "\u221A(", 
    "\u03C0",  "x!",  "abs(",  "\u221B(" 
}; 

public static String[] button_text_values = new String[]{ 
    "^",  "ln(",  "log(",  "\u221A(", 
    "\u03C0",  "!",  "abs(",  "\u221B(" 
}; 

的按鈕P1,SQRT做顯示符號。按下它們時,這些符號也出現在文本視圖中。

但是,同樣不適用於立方根按鈕。它只是顯示了座架「(」。 在按壓TextView的也只顯示支架。

但是所有的計算去正確的。

即按cuberoot然後8確實給結果2

這意味着cuberoot在表達式字符串確實存在,但不顯示在按鈕或TextView的。

如何糾正呢?

謝謝。

+0

你肯定在設備字體的字符存在? –

+0

我該如何檢查? 如果顯示平方根,那麼不應該顯示立方體根目錄? –

+1

沒有..一個角色不會生出另一個:)並且Simon在下面回答......正如我懷疑的那樣。 Char not there。 –

回答

0

您使用的字體可能不包含多維數據集根字符。嘗試不同的字體:

tv1=(TextView)findViewById(R.id.textViewOne); 
bt1=(Button)findViewById(R.id.buttonOne); 
Typeface font= Typeface.createFromAsset(getAssets(), "DejaVuSans.ttf"); 
tv1.setTypeface(font); 
bt1.setTypeface(font); 

也看到這一點:

http://tinkering-is-fun.blogspot.co.uk/2012/04/adding-support-for-more-characters-in.html

+0

和按鈕是什麼? –

+0

這是一樣的,我編輯了我的答案。 – Simon