| | |
| | | */ |
| | | public class ContentFragment extends SupportFragment { |
| | | private static final String ARG_MENU = "arg_menu"; |
| | | private static final String ARG_POS ="arg_position"; |
| | | |
| | | private TextView mTvContent; |
| | | private Button mBtnNext; |
| | |
| | | private int currPos = 0; |
| | | private String mMenu; |
| | | |
| | | public static ContentFragment newInstance(String menu) { |
| | | public static ContentFragment newInstance(String menu,int pos) { |
| | | |
| | | Bundle args = new Bundle(); |
| | | args.putString(ARG_MENU, menu); |
| | | |
| | | args.putInt(ARG_POS,pos); |
| | | ContentFragment fragment = new ContentFragment(); |
| | | fragment.setArguments(args); |
| | | return fragment; |
| | |
| | | Bundle args = getArguments(); |
| | | if (args != null) { |
| | | mMenu = args.getString(ARG_MENU); |
| | | currPos =args.getInt(ARG_POS); |
| | | } |
| | | switch (mMenu){ |
| | | case "档位相关设置": |
| | | currPos = 0; |
| | | //运用反射来实现各个Fragmetn的初始化 |
| | | |
| | | loadRootFragment(R.id.fl_content_container, FragmentSetting0 .newInstance(String.valueOf(currPos)),false,false ); |
| | | break; |
| | | case "常用参数设置": |
| | | currPos = 1; |
| | | loadRootFragment(R.id.fl_content_container, FragmentSetting1.newInstance(String.valueOf(currPos)),false,false ); |
| | | break; |
| | | case "通用评判设置": |
| | | currPos = 2; |
| | | break; |
| | | case "上车起步设置": |
| | | break; |
| | | String clsName= "safeluck.drive.evaluation.fragment.rulefragments.FragmentSetting"; |
| | | |
| | | try { |
| | | Class cls = Class.forName(clsName+currPos); |
| | | Method method= cls.getMethod("newInstance",String.class); |
| | | SupportFragment invoke = (SupportFragment) method.invoke(null, String.valueOf(currPos)); |
| | | loadRootFragment(R.id.fl_content_container, invoke,false,false ); |
| | | } catch (ClassNotFoundException e) { |
| | | e.printStackTrace(); |
| | | } catch (NoSuchMethodException e) { |
| | | e.printStackTrace(); |
| | | } catch (IllegalAccessException e) { |
| | | e.printStackTrace(); |
| | | } catch (InvocationTargetException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |