2014年8月22日 星期五

[Android] string.xml 的 錯誤訊息 error: Multiple substitutions specified in non-positional format; did you mean to add the formatted="false" attribute?

Android 中 的 String.xml 中

若要使用到 String.format() 的話

例如

想顯示 已經下載了 多少 bit 的 檔案  format 成 數字格式

String.format(getResources().getString(R.string.update_downloaded),currentSize ,totalSize);

String.xml 中

 <string name="update_downloaded">Downloaded %s bit  of %s  bit</string>

會出現錯誤訊息

error: Multiple substitutions specified in non-positional format; did you mean to add the formatted="false" attribute?



2014年8月4日 星期一

java 陣列 不重複的值 (使用ArrayList)

今天在實作  barCode 連續掃描時

發現個問題

須要把 掃描到的 barCode 暫存起來

並且存下來的值不重複

對於一個 php 轉java 的新手

第一個想到就是用陣列

在php中  直接  array_push("value");

最後再   array_unique();   就結束了

不過java 沒這麼簡單

 1.java 沒有直接 array_unique 的 function
 2.java 的 Array 需要先預先宣告 長度

ex String barCode[] = new String(10)