作者zorpger (亂世浮生)
看板AndroidDev
標題[問題] Spinner的問題
時間Sun May 22 23:08:51 2016
大家好 我有個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
推 givemepass: 看你資料來源是怎樣 05/22 23:20
→ zorpger: 應該是會用return來get值 05/23 00:06
推 aids61517: 如果你的get1() get2()會在之前就先執行的話,可以先把 05/23 10:24
→ aids61517: 結果存下來,如果一定要在這邊執行的話那就只好這樣 05/23 10:25
→ aids61517: 我不確定reflection可不可以處理你這問題 05/23 10:26
→ zorpger: ya 解決了 先用for包起來 再用this.data.add(get(x))來帶 05/23 18:15