为了账号安全,请及时绑定邮箱和手机立即绑定

原谅我是小白 ,我怎么都感觉看不懂了

在这个VpSimpleFragment类中那个获取VpSimpleFragment对象的方法为什么要这么设计啊?这就是单例模式吗?感觉好像很厉害的样子。。。求解惑啊,为什么要这么弄啊?

正在回答

2 回答

静态工厂模式

0 回复 有任何疑惑可以回复我~
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 ;
	}

附上代码

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
Android-自定义ViewPager指示器
  • 参与学习       30028    人
  • 解答问题       75    个

带领大家实现最火爆的跟随型指示器,学完保准压倒一片

进入课程

原谅我是小白 ,我怎么都感觉看不懂了

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信