課程
/移動開發(fā)
/Android
/Android-自定義ViewPager指示器
在這個VpSimpleFragment類中那個獲取VpSimpleFragment對象的方法為什么要這么設(shè)計?。窟@就是單例模式嗎?感覺好像很厲害的樣子。。。求解惑啊,為什么要這么弄?。?/p>
2016-03-09
源自:Android-自定義ViewPager指示器
正在回答
靜態(tài)工廠模式
private?String?mTitle?; private?final?static?String?BUNDLE_TITLE?=?"title"?; @Override public?View?onCreateView(LayoutInflater?inflater,?ViewGroup?container, Bundle?savedInstanceState)?{ Bundle?bundle?=?getArguments()?; if(bundle!=null){ mTitle?=?bundle.getString(BUNDLE_TITLE)?; } TextView?text?=?new?TextView(this.getActivity())?; text.setText(mTitle); text.setGravity(Gravity.CENTER); return?text; } public?static?VpSimpleFragment?newInstance(String?title){ Bundle?bund?=?new?Bundle(); bund.putString(BUNDLE_TITLE,?title); VpSimpleFragment?fragment?=?new?VpSimpleFragment()?; fragment.setArguments(bund); return?fragment?; }
附上代碼
舉報
帶領(lǐng)大家實現(xiàn)最火爆的跟隨型指示器,學(xué)完保準(zhǔn)壓倒一片
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2016-03-18
靜態(tài)工廠模式
2016-03-09
附上代碼