@@ -34,6 +34,7 @@ public class ExpandableLinearLayout extends LinearLayout implements View.OnClick
3434 private float fontSize ;
3535 private int textColor ;
3636 private int arrowResId ;
37+ private int mPosition ;
3738
3839 public ExpandableLinearLayout (Context context ) {
3940 this (context , null );
@@ -85,10 +86,10 @@ private void findViews() {
8586
8687
8788 public void addItem (View view ) {
88- int childCount = getChildCount ();
8989 if (!useDefaultBottom ){
9090 //如果不使用默认底部
9191 addView (view );
92+ int childCount = getChildCount ();
9293 if (childCount > defaultItemCount ){
9394 hide ();
9495 }
@@ -100,7 +101,8 @@ public void addItem(View view) {
100101 //如果还没有底部
101102 addView (view );
102103 } else {
103- addView (view , childCount - 2 );//插在底部之前
104+ int childCount = getChildCount ();
105+ addView (view , childCount - 1 );//插在底部之前
104106 }
105107 refreshUI (view );
106108 }
@@ -205,13 +207,13 @@ public void toggle() {
205207 isExpand = !isExpand ;
206208
207209 //回调
208- if (mListener != null ){
209- mListener .onStateChanged (isExpand );
210+ if (mStateListener != null ){
211+ mStateListener .onStateChanged (isExpand );
210212 }
211213 }
212214
213215
214- private OnStateChangeListener mListener ;
216+ private OnStateChangeListener mStateListener ;
215217
216218 /**
217219 * 定义状态改变接口
@@ -221,6 +223,25 @@ public interface OnStateChangeListener {
221223 }
222224
223225 public void setOnStateChangeListener (OnStateChangeListener mListener ) {
224- this .mListener = mListener ;
226+ this .mStateListener = mListener ;
227+ }
228+
229+
230+ public void setOnItemClickListener (final OnItemClickListener listener ){
231+ int endIndex = useDefaultBottom ? getChildCount () - 1 : getChildCount ();//如果是使用默认底部,则结束的下标是到底部之前
232+ for (int i = 0 ; i < endIndex ;i ++){
233+ View view = getChildAt (i );
234+ final int position = i ;
235+ view .setOnClickListener (new OnClickListener () {
236+ @ Override
237+ public void onClick (View v ) {
238+ listener .onItemClick (v ,position );
239+ }
240+ });
241+ }
242+ }
243+
244+ public interface OnItemClickListener {
245+ void onItemClick (View view ,int position );
225246 }
226247}
0 commit comments