获取string-array

Resources res = getResources();
String[] test = res.getStringArray(R.array.test);
for(int i = 0; i < test.length; i++){
System.out.println(test[i]);
}

处理复数的字符串(我也不是很懂)

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="holidays">
<item >新年</item>
<item >端午节</item>
<item >中秋节</item>
</string-array>
<plurals name="holiday_summary">
<item quantity="one">今年有一天假日</item>
<item quantity="other">今年有%d天假日</item>
</plurals>

</resources>

java代码

package src.com;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;

public class InitActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

/*Intent i = new Intent(this,NotifyService.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startService(i);*/

//调用字符串
Resources res = getResources();
String[] holidays = res.getStringArray(R.array.holidays);
String holiday_comment = res.getQuantityString(R.plurals.holiday_summary, holidays.length);
System.out.println("1----" + holiday_comment);
if(holidays.length > 1){
holiday_comment = String.format(holiday_comment, holidays.length);
}

System.out.println("2----" + holiday_comment);

for(int i = 0; i < holidays.length; i++){
System.out.println(holidays[i]);
}
}
}

你可能感兴趣的:(String)