を文字列配列を取得するには、私は、文字列の配列項目を取得するために作られたコードです。しかしアンドロイド - リソースから以下
<string-array name="menu">
<item>1</item>
<item>2</item>
<item>3</item>
</string-array>
、:
String[] menuArray;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ScrollView sv = new ScrollView(this);
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
sv.addView(ll);
// Create an ArrayAdapter that will contain all list items
ArrayAdapter<String> adapter;
menuArray = getResources().getStringArray(R.array.menu);
for(int i = 0; i < menuArray.length; i++)
{
Button b = new Button(this);
b.setText(menuArray[i]);
ll.addView(b);
}
this.setContentView(sv);
}
これはのstrings.xmlファイルですR.array.menuこの問題はコンパイル時に発生します。 ADT 14以降、リソースフィールドはスイッチのケースとして使用できません。 詳細については、この修正プログラムを呼び出してください。
うん、私はあなたからスナップショットを提供することができますあなたが見たい場合はエミュレータ。 ** count()**の定義が提供されていないので、try catchブロックと一緒に変数** x **の使用をスキップしました。 –
スイッチにリソースIDを使用していますか?チェック[これ](http://stackoverflow.com/questions/8387777/what-is-migrate-android-code) –
私はそれを解決..それは単に私がstrings.xmlからapp_nameを移動するためですLOL –