@@ -143,6 +143,7 @@ public abstract class ExtendableListView extends AbsListView {
143143 private FlingRunnable mFlingRunnable ;
144144
145145 protected boolean mClipToPadding ;
146+ private PerformClick mPerformClick ;
146147
147148 /**
148149 * A class that represents a fixed view in a list, for example a header at the top
@@ -939,7 +940,17 @@ private boolean onTouchUpScrolling(final MotionEvent event) {
939940 }
940941
941942 private boolean onTouchUpTap (final MotionEvent event ) {
942- // TODO : implement onListItemClick stuff here
943+ if (mPerformClick == null ) {
944+ invalidate ();
945+ mPerformClick = new PerformClick ();
946+ }
947+ final int motionPosition = mMotionPosition ;
948+ if (!mDataChanged && mAdapter .isEnabled (motionPosition )) {
949+ final PerformClick performClick = mPerformClick ;
950+ performClick .mClickMotionPosition = motionPosition ;
951+ performClick .rememberWindowAttachCount ();
952+ performClick .run ();
953+ }
943954 return true ;
944955 }
945956
@@ -2679,4 +2690,40 @@ public void onRestoreInstanceState(Parcelable state) {
26792690 }
26802691 requestLayout ();
26812692 }
2693+
2694+ private class PerformClick extends WindowRunnnable implements Runnable {
2695+ int mClickMotionPosition ;
2696+
2697+ public void run () {
2698+ if (mDataChanged ) return ;
2699+
2700+ final ListAdapter adapter = mAdapter ;
2701+ final int motionPosition = mClickMotionPosition ;
2702+ if (adapter != null && mItemCount > 0 &&
2703+ motionPosition != INVALID_POSITION &&
2704+ motionPosition < adapter .getCount () && sameWindow ()) {
2705+ final View view = getChildAt (motionPosition ); // a fix by @pboos
2706+
2707+ if (view != null ) {
2708+ performItemClick (view , motionPosition + mFirstPosition , adapter .getItemId (motionPosition ));
2709+ }
2710+ }
2711+ }
2712+ }
2713+
2714+ /**
2715+ * A base class for Runnables that will check that their view is still attached to
2716+ * the original window as when the Runnable was created.
2717+ */
2718+ private class WindowRunnnable {
2719+ private int mOriginalAttachCount ;
2720+
2721+ public void rememberWindowAttachCount () {
2722+ mOriginalAttachCount = getWindowAttachCount ();
2723+ }
2724+
2725+ public boolean sameWindow () {
2726+ return hasWindowFocus () && getWindowAttachCount () == mOriginalAttachCount ;
2727+ }
2728+ }
26822729}
0 commit comments