Created
February 25, 2014 05:55
-
-
Save tmf16/9203495 to your computer and use it in GitHub Desktop.
ListViewを継承してonTouchEventを実装するとNullPointerException(Android 2.3以前)になるので回避策でgetChildCount使う実装
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HogeListView extends ListView { | |
public HogeListView(Context context) { | |
super(context); | |
} | |
public HogeListView(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
} | |
public HogeListView(Context context, AttributeSet attrs, int defStyle) { | |
super(context, attrs, defStyle); | |
} | |
@Override | |
public boolean onTouchEvent(MotionEvent ev) { | |
switch (ev.getAction()) { | |
case MotionEvent.ACTION_MOVE: | |
// task | |
break; | |
default: | |
break; | |
} | |
if (getChildCount() == 0) { | |
return false; | |
} | |
return super.onTouchEvent(ev); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
参考
http://stackoverflow.com/questions/12473625/nullpointerexception-at-android-widget-abslistview-contentfitsabslistview-java