Reputation: 37
I have tried searching but I couldn't find the answer to my problem. I'm trying to simply display the value of an int. I want pass it as an int. Here is my code. For some reason instead of diplaying the actual number, its displaying %d.
java code:
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 code from 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 code from 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>
Thanks in advance!
Upvotes: 2
Views: 754
Reputation: 5106
Format string syntax using Java's Formatter
class is actually different from the syntax you're using, try changing the "aaa" string to the following:
<string name="aaa">hello %1$ </string>
To understand what's going on you can read more about the syntax here: http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Formatter.html#syntax
Upvotes: 1