我想創建了一個布局,類似 Google play's。我使用 ViewPager ,需要 fragment。我查了一些資料說一個 fragment 需要一個空的構造函數,但是事例中在 developer.android.com 不包含一個構造函數。事例代碼如下:public static class DemoObjectFragment extends Fragment {
public static final String ARG_OBJECT = "object";
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
// The last two arguments ensure LayoutParams are inflated
// properly.
View rootView = inflater.inflate(
R.layout.fragment_collection_object, container, false);
Bundle args = getArguments();
((TextView) rootView.findViewById(android.R.id.text1)).setText(
Integer.toString(args.getInt(ARG_OBJECT)));
return rootView;
}
}需要在一個fragment中包含一個構造函數嗎?或者直接省去構造函數?
添加回答
舉報
0/150
提交
取消
