Syntax error on token "QUOTE", VariableDeclaratorId expected after this token
I've posted a bigger chunk of the code below. You can see that initially QUOTE was procedural- coded in place. I'm trying to learn how to use declarative design so I want to do the same thing but by using resources. It seems like I need to access the string.xml thru the @R.id tag and identify QUOTE with that string value. But I don't know enough to negotiate this. Any tips? Thanks!
public class circle extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new GraphicsView(this));
}
static public class GraphicsView extends View {
//private static final String QUOTE = "Happy Birthday to David.";
private final String QUOTE = getString(R.string.quote);
.....
@Override
protected void onDraw(Canvas canvas) {
/开发者_运维技巧/ Drawing commands go here
canvas.drawPath(circle, cPaint);
canvas.drawTextOnPath(QUOTE, circle, 0, 20, tPaint);
}
}
Basically I want to have the same text but as a resource in strings.xml
At minimum, you heed a file named res/values/strings.xml
with the following:
<resources>
<string name="quote">Happy Birthday to David.</string>
</resources>
You then use getString(R.string.quote)
to get at the string value in your Java code. Note that you already probably have a res/values/strings.xml
file, created for you when the project was created, so just add the <string>
element shown above alongside the other such elements in that file.
Can someone please educate me a little and recommend a good resource for these type of questions? I'm using HelloAndroid at the moment and I also have "Beginning Android".
String resources are covered on pages 175-180 of Beginning Android. A current version of the sample project from that section can be found here.
精彩评论