2
我嘗試過搜索,但找不到問題的答案。我試圖簡單地顯示一個int的值。我想把它作爲一個int來傳遞。這是我的代碼。出於某種原因,而不是實際的數字,它顯示%d。將int傳遞給.xml以供Android應用程序使用
java代碼:
package ebike.picture.com;
import android.app.Activity;
import android.os.Bundle;
public class PictureActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String hello = getString(R.string.aaa, 10);
}
}
XML代碼的strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, PictureActivity!</string>
<string name="app_name">Picture</string>
<string name="aaa">hello %d </string>
</resources>
XML代碼從main.xml中:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/aaa" />
</LinearLayout>
提前感謝!使用Java的Formatter
類