1414
1515package apijson .demo .client .view ;
1616
17+ import java .util .List ;
18+
19+ import zuo .biao .library .base .BaseView ;
20+ import zuo .biao .library .util .Log ;
21+ import zuo .biao .library .util .StringUtil ;
1722import android .annotation .SuppressLint ;
1823import android .app .Activity ;
1924import android .content .res .Resources ;
2227import android .view .View .OnClickListener ;
2328import android .view .View .OnLongClickListener ;
2429import android .view .ViewGroup ;
25-
26- import java .util .ArrayList ;
27- import java .util .List ;
28-
2930import apijson .demo .client .R ;
3031import apijson .demo .client .model .CommentItem ;
3132import apijson .demo .client .view .CommentView .OnCommentClickListener ;
32- import zuo .biao .library .base .BaseView ;
33- import zuo .biao .library .util .Log ;
34- import zuo .biao .library .util .StringUtil ;
3533
3634/**评论容器
3735 * @author Lemon
3836 * @use
39- CommentContainerView commentContainerView = new CommentContainerView(context, inflater);
40- adapter中使用convertView = commentContainerView.getView();//[具体见.DemoAdapter] 或 其它类中使用
41- containerView.addView(commentContainerView.getConvertView());
42- commentContainerView.bindView(data);
43- commentContainerView.setOnClickPictureListener(onClickPictureListener);//非必需
44- commentContainerView.setOnDataChangedListener(onDataChangedListener);data = commentContainerView.getData();//非必需
45- commentContainerView.setOnClickListener(onClickListener);//非必需
46- ...
37+ * <br> CommentContainerView commentContainerView = new CommentContainerView(context, resources);
38+ * <br> adapter中使用:[具体参考.DemoAdapter2(getView使用自定义View的写法)]
39+ * <br> convertView = commentContainerView.createView(inflater, position, viewType);
40+ * <br> commentContainerView.bindView(data, position, viewType);
41+ * <br> 或 其它类中使用:
42+ * <br> containerView.addView(commentContainerView.createView(inflater));
43+ * <br> commentContainerView.bindView(data);
44+ * <br> 然后
45+ * <br> commentContainerView.setOnCommentClickListener(onCommentClickListener);//非必需
46+ * <br> commentContainerView.setOnDataChangedListener(onDataChangedListener);data = commentContainerView.getData();//非必需
47+ * <br> commentContainerView.setOnClickListener(onClickListener);//非必需
48+ * <br> ...
4749 */
4850public class CommentContainerView extends BaseView <List <CommentItem >> {
4951 private static final String TAG = "CommentContainerView" ;
@@ -84,38 +86,14 @@ public View createView(LayoutInflater inflater) {
8486
8587 @ Override
8688 public void bindView (List <CommentItem > list ){
87- llCommentContainerViewContainer .setVisibility (list == null || list .isEmpty () ? View .GONE : View .VISIBLE );
88- if (list == null ) {
89- Log .w (TAG , "bindView data_ == null >> data_ = new List<CommentItem>();" );
90- list = new ArrayList <CommentItem >();
91- }
9289 this .data = list ;
9390
94- // 评论
95- setComment (list );
96- }
97-
98-
99- private int maxShowCount = 3 ;
100- /**设置最多显示数量,超过则折叠
101- * @param maxShowCount <= 0 ? 显示全部 : 超过则折叠
102- */
103- public void setMaxShowCount (int maxShowCount ) {
104- this .maxShowCount = maxShowCount ;
105- }
106-
107-
108- /**设置评论
109- * @param list
110- */
111- public void setComment (List <CommentItem > list ) {
11291 int count = list == null ? 0 : list .size ();
11392 boolean showMore = maxShowCount > 0 && count > maxShowCount ;
11493
11594 tvCommentContainerViewMore .setVisibility (showMore ? View .VISIBLE : View .GONE );
116-
117- llCommentContainerViewContainer .removeAllViews ();
11895 llCommentContainerViewContainer .setVisibility (count <= 0 ? View .GONE : View .VISIBLE );
96+ llCommentContainerViewContainer .removeAllViews ();//TODO 貌似比 只在count > 0时执行 性能更好,有待具体测试
11997
12098 if (count > 0 ) {
12199 if (showMore ) {
@@ -125,10 +103,21 @@ public void setComment(List<CommentItem> list) {
125103 addCommentView (i , list .get (i ));
126104 }
127105 }
106+
107+ }
128108
109+
110+ private int maxShowCount = 3 ;
111+ /**设置最多显示数量,超过则折叠
112+ * @param maxShowCount <= 0 ? 显示全部 : 超过则折叠
113+ * @must 在bindView前调用
114+ */
115+ public void setMaxShowCount (int maxShowCount ) {
116+ this .maxShowCount = maxShowCount ;
129117 }
130118
131119
120+
132121 /**添加评论
133122 * @param index
134123 * @param comment
0 commit comments