[問題] Spinner的問題

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

Links booklink

Contact Us: admin [ a t ] ucptt.com