0

string.xml で書式設定された文字列を参照しようとしています。私はグーグルで調べていて、この良い記事を見つけました: http://developer.android.com/guide/topics/resources/string-resource.html

私はそれを細部に至るまでたどりましたが、印刷されたテキストは本来あるべきものではありません.

まず、リソースの下のstrings.xmlで、次のように定義しました。

<string name="print_binary">This is the printout: %1$s</string>

そして、.javaに次のように入れました:

String fromString = "one";
Resources res = getResources();

onScreen = String.format(res.getString(R.string.print_binary), fromString);

これにより、画面に次のテキストが表示されます: This is the printout: %1$s

ご意見をお聞かせください

4

2 に答える 2

0

よかった、次のような入力を完全に見逃していました

TextView show = (TextView) findViewById(R.id.tvDisplay); 
show.setText(onScreen); 

そして、TextView オブジェクトの ID を追加します。深夜すぎる。String.format() ステートメントは必要ないようです。それについて調べます。ご協力ありがとうございました!

于 2012-10-21T19:26:42.443 に答える
0

以下を使用できます。

onScreen = res.getString(R.string.print_binary, fromString);

于 2012-08-04T20:29:27.987 に答える