Repository navigation
Expand file tree
/
Copy pathBaseViewLayout.java
More file actions
75 lines (60 loc) · 2.06 KB
/
Copy pathBaseViewLayout.java
File metadata and controls
75 lines (60 loc) · 2.06 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
/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.*/
package apijson.demo.client.view;
import android.app.Activity;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import apijson.demo.client.activity_fragment.UserActivity;
import zuo.biao.library.base.BaseView;
/**BaseView布局类,可直接写在layout文件内
* @author Lemon
* @param <T>
* @see UserActivity#initView()
* @use
* <br> BaseViewLayout<T> bvl = (BaseViewLayout<T>) findViewById(R.id.bvl);
* <br> bvl.createView(new ModelView(context, getResources()));
* <br> bvl.bindView(model);
*/
public class BaseViewLayout<T> extends FrameLayout {
private static final String TAG = "BaseViewLayout";
public BaseViewLayout(Context context) {
super(context);
init((Activity) context);
}
public BaseViewLayout(Context context, AttributeSet attrs) {
super(context, attrs);
init((Activity) context);
}
public BaseViewLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init((Activity) context);
}
private Activity context;
protected void init(Activity context) {
this.context = context;
}
public BaseView<T> bv;
public void createView(BaseView<T> bv) {
this.bv = bv;
removeAllViews();
super.addView(bv.createView(context.getLayoutInflater()));
bindView(null);
}
@Override
public void addView(View child) {
throw new UnsupportedOperationException(TAG + "不支持该方法");
}
public void bindView(T data) {
bv.bindView(data);
}
}