-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractFragment.java
More file actions
87 lines (74 loc) · 2.31 KB
/
AbstractFragment.java
File metadata and controls
87 lines (74 loc) · 2.31 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
81
82
83
84
85
86
87
package com.administrator.abstractviewsample.AbstractView;
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
/**
* Created by huangxy on 2016/3/3.
* https://github.com/GitSmark/AbstractView
*/
public abstract class AbstractFragment extends Fragment implements OnClickListener {
protected abstract int getLayoutResId();
protected abstract void initView();
protected View view = null;
@Override
@Deprecated
public void onAttach(Activity activity) {
// TODO Auto-generated method stub
super.onAttach(activity);
}
@Override
@Nullable
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
// TODO Auto-generated method stub
view = inflater.inflate(getLayoutResId(), container, false);
beforeInitView();
initView();
getData();
Other();
return view;
}
@SuppressWarnings("uncheckedz")
protected <T extends View> T $find(int Resid) {
return (T) view.findViewById(Resid);
}
@SuppressWarnings("uncheckedz")
protected <T extends View> T $find(View v, int Resid) {
return (T) v.findViewById(Resid);
}
@SuppressWarnings("uncheckedz")
protected <T extends View> T $click(int Resid) {
T t = (T) view.findViewById(Resid);
try {t.setOnClickListener(this);
}catch (Exception e){}
return t;
}
@SuppressWarnings("uncheckedz")
protected <T extends View> T $click(View v, int Resid) {
T t = (T) v.findViewById(Resid);
try {t.setOnClickListener(this);
}catch (Exception e){}
return t;
}
@SuppressWarnings("uncheckedz")
protected <T extends View> T $onClick(int Resid, OnClickListener listener) {
T t = (T) view.findViewById(Resid);
try {t.setOnClickListener(listener);
}catch (Exception e){}
return t;
}
@SuppressWarnings("uncheckedz")
protected <T extends View> T $onClick(View v, int Resid, OnClickListener listener) {
T t = (T) v.findViewById(Resid);
try {t.setOnClickListener(listener);
}catch (Exception e){}
return t;
}
public void beforeInitView() {}
public void getData() {}
public void Other() {}
}