量化字串:安卓權威編程 13.7挑戰練習-最佳化字串資源顯示

來源:互聯網
上載者:User

標籤:mesi   XML   anti   ural   製造   ant   int   one   str   

注意到沒有,只有一條crime記錄的時候,顯示總記錄數的子標題會顯示:1 crimes。請改正這個粗心的語法錯誤。
實現思路上,你可以在代碼中準備不同字串資源分情況使用,但這會給應用本地化製造麻煩。比較好的做法是使用複數字串資源(又稱為量化字串)。
首先,在strings.xml檔案中定義複數字串資源。

<plurals name="subtitle_plural"><item quantity="one">%1$s crime</item><item quantity="other">%1$s crimes</item></plurals>

然後,使用 getQuantityString 方法正確處理單複數問題。

1 int crimeSize = crimeLab.getCrimes().size();2 String subtitle = getResources()3 .getQuantityString(R.plurals.subtitle_plural, crimeSize, crimeSize);

 

量化字串:安卓權威編程 13.7挑戰練習-最佳化字串資源顯示

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.