[問題] Spinner的問題

看板AndroidDev作者 (亂世浮生)時間9年前 (2016/05/22 23:08), 編輯推噓2(204)
留言6則, 3人參與, 最新討論串1/1
大家好 我有個Spinner的問題想要問一下 Spinner 要加選項的話要用this.xxx.add("");去加選項 我現在有個問題 假如 get1=a , get2=b ,get3=c , get4=d , get5=e 就會是以下的寫法 this.data = new ArrayList<CharSequence>(); this.data.add(get1()); this.data.add(get2()); this.data.add(get3()); this.data.add(get4()); this.data.add(get5()); this.spdata = (Spinner) super.findViewById(R.id.data); this.adapterdata = ArrayAdapter <CharSequence>(this, android.R.layout.simple_spinner_item, this.data); this.adapterdata.setDropDownViewResource( android.R.layout.simple_spnner_dropdown_item); 我想問的是有沒有辦法能夠簡化this.data.add這邊 假如有get100 , 不就要add100行 謝謝!! -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.240.49.31 ※ 文章網址: https://www.ptt.cc/bbs/AndroidDev/M.1463929734.A.D21.html

05/22 23:20, , 1F
看你資料來源是怎樣
05/22 23:20, 1F

05/23 00:06, , 2F
應該是會用return來get值
05/23 00:06, 2F

05/23 10:24, , 3F
如果你的get1() get2()會在之前就先執行的話,可以先把
05/23 10:24, 3F

05/23 10:25, , 4F
結果存下來,如果一定要在這邊執行的話那就只好這樣
05/23 10:25, 4F

05/23 10:26, , 5F
我不確定reflection可不可以處理你這問題
05/23 10:26, 5F

05/23 18:15, , 6F
ya 解決了 先用for包起來 再用this.data.add(get(x))來帶
05/23 18:15, 6F
文章代碼(AID): #1NGSk6qX (AndroidDev)