endian11
2020-09-28 6a65502e55b100159eeb5bd10e7b30eeac20dc5d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package safeluck.drive.evaluation.fragment.shop;
 
 
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
 
import androidx.annotation.Nullable;
 
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
 
import me.yokeyword.fragmentation.SupportFragment;
import me.yokeyword.fragmentation.anim.DefaultNoAnimator;
import me.yokeyword.fragmentation.anim.FragmentAnimator;
import safeluck.drive.evaluation.R;
import safeluck.drive.evaluation.fragment.BaseSettingFragment;
import safeluck.drive.evaluation.fragment.rulefragments.FragmentSetting0;
import safeluck.drive.evaluation.fragment.rulefragments.FragmentSetting1;
 
/**
 * Created by YoKeyword on 16/2/9.
 */
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,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;
    }
 
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
 
        Bundle args = getArguments();
        if (args != null) {
            mMenu = args.getString(ARG_MENU);
            currPos =args.getInt(ARG_POS);
        }
        //运用反射来实现各个Fragmetn的初始化
 
        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();
        }
    }
 
    @Override
    public FragmentAnimator onCreateFragmentAnimator() {
        return new DefaultNoAnimator();
    }
 
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_content, container, false);
        initView(view);
        return view;
    }
 
    private void initView(View view)  {
//        mTvContent = (TextView) view.findViewById(R.id.tv_content);
 
 
    }
 
    @Override
    public boolean onBackPressedSupport() {
        // ContentFragment是ShopFragment的栈顶子Fragment,可以在此处理返回按键事件
        return super.onBackPressedSupport();
    }
}