這應該很簡單,但是會讓我瘋狂。從數組中保存的字符串資源設置textview文本
我在佈局中有以下,而不是問題。
<TextView
android:id="@+id/birdinfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#00009c"
android:text="The Robin is a popular bird"
/>
然後我有設置了字符串資源的列表,這些陣列我有
private Integer[] DetailIds = {
R.string.barnaclegoose,
R.string.barnowl,
R.string.bewicksswan,
R.string.blackbird,
R.string.blackcap_male};
所以我只是想做到這一點!
TextView detail = (TextView)findViewById(R.id.birdinfo);
detail.setText(DetailIds[0]);
setContentView(R.layout.main);
但是這會導致強制關閉錯誤。
字符串資源看起來是這樣的(當然沒有頁眉和頁腳信息
<string name="barnaclegoose">What a wonderful goose!</string>
添加到這個問題,如果我直接使用資源到資源
detail.setText(R.string.barnaclegoose);
例如,我仍然得到一個零例外!我確信我以前做過這個,但也許我錯過了明顯???
任何想法讚賞。
(Eclipse,Android 1.5,Emulator with 1.5)
你確定,你可以在整型內舉行的字符串陣列? ;-) – poeschlorn 2010-06-29 11:15:55
發佈表示的堆棧跟蹤 – Budius 2016-06-25 09:10:00