我有一个Fragment
空构造函数,我需要能够访问字符串资源,以便我可以创建片段的构造组件。
我知道我可能应该使用newInstance()
构造函数而不是构造函数,但构造函数到目前为止一直在工作,使用Bundle
.
我的片段构造函数如下:
public SideMenuView(Context ctx) {
menuItems = new MenuItem[] {
new MenuItem(R.drawable.one_icon, ctx.getResources().getString(R.string.one), R.id.imgChevron),
new MenuItem(R.drawable.two_icon, ctx.getResources().getString(R.string.two), R.id.imgChevron),
new MenuItem(R.drawable.three_icon, ctx.getResources().getString(R.string.three), R.id.imgChevron)
};
fragCache = new Fragment[menuItems.length];
}