-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBaseFragment.java
More file actions
80 lines (67 loc) · 1.9 KB
/
Copy pathBaseFragment.java
File metadata and controls
80 lines (67 loc) · 1.9 KB
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
package com.miaoyi.work.fragment;
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.miaoyi.work.R;
import com.miaoyi.work.activity.BaseActivity;
/**
* Created by administrato on 2016/8/23.
*/
public abstract class BaseFragment extends Fragment {
protected BaseActivity mActivity;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(getLayoutId(), container, false);
initView(view, savedInstanceState);
return view;
}
/**
* init view
*
* @param view parent
* @param savedInstanceState saved parameters
*/
protected abstract void initView(View view, Bundle savedInstanceState);
/**
* get Layout Id
*
* @return int ID
*/
protected abstract int getLayoutId();
/**
* get holding activity
*
* @return BaseActivity
*/
protected BaseActivity getHoldingActivity() {
return mActivity;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
this.mActivity = (BaseActivity) activity;
}
/**
* add Fragment
*
* @param fragment
*/
protected void addFragment(BaseFragment fragment, String title) {
if (null != fragment) {
getHoldingActivity().addFragment(fragment, title);
}
}
/**
* remove Fragment
*/
protected void removeFragment() {
getHoldingActivity().removeFragment();
}
}